Programming

Interactive Heating and Cooling Curves

Heating and cooling curves are graphical representations that show how the temperature of a substance changes as heat is added or removed over time. They illustrate the behavior of substances as they go through different states—solid, liquid, and gas.

Heating Curve: This curve shows how the temperature of a substance increases as it absorbs heat. The curve typically rises as the substance heats up, with plateaus indicating phase changes, where the substance absorbs energy but its temperature remains constant. Check out the heating curves for water and nitrogen using the drop-down menu.

Cooling Curve: This curve is the opposite of the heating curve. It shows how the temperature decreases as the substance loses heat. Like the heating curve, it also has plateaus where phase changes occur, but this time, the substance releases energy. In addition to water, you can also see the cooling curve for ethanol.

With these ChatGPT-generated interactive graphs, users can change the rate of heat input or released from the substance. They can also read the descriptions that explain the changes in the average PE and KE of the molecules during each process.

Geiger–Müller counter simulation

A Geiger-Muller (GM) counter is an instrument for detecting and measuring ionizing radiation. It operates by using a Geiger-Muller tube filled with gas, which becomes ionized when radiation passes through it. This ionization produces an electrical pulse that is counted and displayed, allowing users to determine the presence and intensity of radiation.

Svjo-2, CC BY-SA 3.0, via Wikimedia Commons

This simulation (find it at https://physicstjc.github.io/sls/gm-counter) allows students to explore the random nature of radiation and the significance of accounting for background radiation in experiments. Here’s a guide to help students investigate these concepts using the simulation.

Exploring Background Radiation

Q1: Set the source to “Background” and start the count. Observe the count for a few minutes. What do you notice about the counts recorded?

A1: The counts recorded are relatively low and vary randomly. This reflects the background radiation which is always present.


Q2: Why is it important to measure background radiation before testing other sources?

A2: Measuring background radiation is important to establish a baseline level of radiation. This helps in accurately identifying and quantifying the additional radiation from other sources.


Investigating a Banana as a Radiation Source

Q3: Change the source to “Banana” and reset the data. Start the count and observe the readings. How do the counts from the banana compare to the background radiation?

A3: The counts from the banana are higher than the background radiation. This is because bananas contain a small amount of radioactive potassium-40.


Q4: How do the counts per minute (CPM) for the banana vary over time? Is there a pattern or do the counts appear random?

A4: The counts per minute for the banana vary over time and appear random, reflecting the stochastic nature of radioactive decay.


Exploring a Cesium-137 Source

Q5: Set the source to “Cesium-137” and reset the data. Start the count and observe the readings. How do the counts from Cesium-137 compare to both the background radiation and the banana?

A5: The counts from Cesium-137 are significantly higher than both the background radiation and the banana. This is because Cesium-137 is a much stronger radioactive source.


Q6: What do the counts per minute (CPM) tell you about the intensity of the Cesium-137 source compared to the other sources?

A6: The CPM for Cesium-137 is much higher, indicating a higher intensity of radiation compared to the background and banana sources.


Understanding the Random Nature of Radiation

Q7: By looking at the sample counts, can you predict the next count value? Why or why not?

A7: No, you cannot predict the next count value because radioactive decay is a random process. Each decay event is independent of the previous ones.


Q8: How can you use the background radiation measurement to correct the readings from the banana and Cesium-137 sources?

A8: You can subtract the average background CPM from the CPM of the banana and Cesium-137 sources to get the corrected readings, isolating the radiation from the specific sources.


Stationary Wave Interactive using ChatGPT

I wanted to challenge ChatGPT to produce a complex interactive in order to prove that it is possible for teachers without much programming background to work with it as well.

This time, it was a lot more trial and error. The first major problem was when I thought the usual javascript library for graphs, Chart.JS would work. However, what I produced as a wonky wave in both directions that somehow attenuated as it travelled even though the equation of the waves did not have a decay factor.

The equation was generated by ChatGPT but looked like a normal sinusoidal function to me:

var y1 = Math.sin(2 * Math.PI * x / wavelength - 2 * Math.PI * time / period);

This is what the wonky graph looks like:

My suspicion is that Chart.JS makes use of points to form the curve so animating so many points at one go put too much demand on the app.

I then asked ChatGPT to suggest a different library. It then proceeded to make a new app with Plotly.JS, which works much better with moving graphs. This impressed me. I am learning so much with this new workflow. The final interactive graph can be found here:

I decided to add more functions after the first page was ready. While it took me about an hour to get the first page right with about 15 iterations mainly due to the wrong javascript library used, adding in more sliders to make the interactive more complex with variable wavelengths, periods and amplitudes took less than 10 minutes.

I shall just share the prompts that were given after I realised that plotly.js is the way to go.

Prompts for the index page:

  1. Create a graph using plotly.js with a vertical axis for displacement of wave particles and a horizontal axis for distance moved by a wave. .
  2. Draw the curve of an infinitely long transverse wave moving along the horizontal axis.
  3. Create another infinitely long transverse wave of the same wavelength moving in the opposite direction along the same horizontal axis. Represent them in different colours.
  4. Use a slider to change the period of oscillation of both waves and another slider to change the wavelength of the waves.
  5. Each wave should have the same wavelength.
  6. Revised prompt: Keep the vertical axis fixed in height, equal to the maximum possible amplitude of the third wave.
  7. Revised prompt: Keeep the legend of the chart to the bottom so that the horizontal axis length is fixed at 640 pixels

Prompts for the second page:

  1. Have separate sliders for the amplitudes, periods and wavelengths of wave 1 and wave 2.
  2. Display the values of the sliders next to them.

Delight – a web-based board game on electricity

I had previously shared about this physical board game that I designed to teach electricity concepts. Now, with ChatGPT’s help, I have managed to produce a simple implementation of the board game so that there is no need to print and cut out the pieces anymore.

However, the game is still unable to detect if the light bulb will light up and automatically change the image colour or add the scores. That will require further complex programming due to the many possible outcomes for this game.

https://physicstjc.github.io/sls/delight/index.html

The rules of the game are as such:

  1. Players will take turns to connect their own bulbs to the terminals while trying to sabotage their opponent’s bulbs.
  2. Players will take turns to place one piece on the 4-by-4 game board by clicking to select the electrical component and clicking on the square on the board to place it.
  3. Upon placing the piece, the player can also turn that piece in any orientation (by clicking on it) within the same turn.
  4. Players can choose to use up to two turns at any point in the game to rotate any piece that had been placed by any player.
  5. In other words, each player has 9 turns: 7 placement turns and 2 rotation turns.

At lower levels, students can compete to see who has the most lit bulbs. However, they will need to be able to identify which light bulbs are lit. Do watch out for short-circuits.

At higher levels, students can compete to see whose light bulbs has the most total electrical power, with some calculations involved.

Dice Simulation to Teach Probability

A dice simulation is an excellent tool for teaching probability because it provides a hands-on, visual way for students to understand the concepts of probability through experimentation and observation.

In the simplest demonstration, students should be able to predict and observe that a fair six-sided dice gives equal probability of outcome and hence, almost equal total occurrences given a large-enough sample size.

Students can then be asked to predict the probability distribution if given two dice.

The good thing is that with simulations, students get to compare the experimental probabilities they calculated with the theoretical probabilities and discuss any discrepancies and reasons for them. This allows students to understand the concept of randomness and how experimental results may vary from theoretical expectations due to chance.

Click here to access the simulator and here to download it for SLS.

The prompts used for ChatGPT are as follow:

Provide the code for the following in a single html file:

  1. Create a 6-sided dice simulator where the user can click on the image of a dice, the dice image will change randomly and the final result will be shown on the image.
  2. The dice image will be represented by the file “dice1.png” for the number 1, “dice2.png” for number 2, “dice3.png” for number 3 and so on. The image size is 80 pixels by 80 pixels.
  3. The default setting shows one dice. The initial image shown is “dice1.png”.
  4. Create a button to cast the dice.
  5. Create a bar chart with 6 vertical columns at the bottom that shows the frequency of the numbers obtained by the dice. Adjust the bar chart to show all 6 possible outcomes.
  6. Each time the dice is cast and the result is shown, it is added to a list shown below the chart.
  7. Create a button for an option to toggle between the use of one dice or two die. When this button is clicked, the list of results and the bar chart is cleared. The initial images shown are both “dice1.png”. If two die are used, both die will be shown side by side.
  8. Both die will be cast when clicking on either dice. The bar chart now shows the frequency of the total of the numbers obtained by the die. Adjust the bar chart such that it now has 12 vertical columns show all 12 possible outcomes.
  9. The total number for each toss will be shown in the list.

Bouncing Ball Animation using Python

For a fullscreen view, visit https://www.glowscript.org/#/user/wboson2007/folder/MyPrograms/program/Bouncing

Modified this python simulation from Dr Darren Tan’s work at https://sciencesamurai.trinket.io/a-level-physics-programming#/collisions/bouncing-ball

Wanted to try out a different way of creating simulations. Added the acceleration-time graph in place of his energy-time graph, in preparation for the teaching of kinematics. Also assuming no energy loss during collisions for simplicity.

For Singapore teachers, I have submitted a request to SLS for this URL to be whitelisted for embedding. Once approved, glowscript simulations can be embedded as part of the lesson. For the time being, a URL link out to the simulation will have to do.