A-level Topics

Interactive Graph with Javascript

I was experimenting with using generative AI to create an interactive graph that could be used to amend the animation of a moving particle, for the topic of kinematics. Students are able to move the four points on the velocity time graph to manipulate the movement. I kept the graph to straight lines between each point to keep things simple.

The vertical axis toggles between displacement and velocity. This will be yet another way for students to learn about how the velocity-time graph affects motion. I have found that many students are confused between displacement and velocity. The app’s ability for them to vary the velocity graph and then make predictions of the resulting displacement graph and the movement should be worth the effort.

Random displacement and velocity simulation

Oftentimes, the kinematics graphs that students see in their textbooks are very clean and simple. In nature, movement is often haphazard and to simulate such movement in one dimension, I generated this (https://physicstjc.github.io/sls/random-displacement/index.html) using ChatGPT 4o.

There is a drop-down menu that allows users to toggle between displacement and velocity graphs.

In a displacement-time graph, the displacement is plotted on the y-axis and time on the x-axis. A positive displacement represents a position to the right of the origin while a negative displacement is to its left. The slope of this graph represents the object’s velocity; a steeper slope indicates a higher velocity. A positive slope means the object is moving forward, a negative slope indicates it is moving backward, and a zero slope shows the object is at rest. For example, in uniform motion, the displacement-time graph is a straight line with a constant slope, reflecting constant velocity.

Conversely, in a velocity-time graph, velocity is on the y-axis and time on the x-axis. The area under the velocity-time graph represents the object’s displacement. Areas above the time axis denote positive displacement, while areas below indicate negative displacement.

AI prompts to generate web-based quizzes

With a set of questions on the equations of rectilinear motion as an example, the following quiz was generated using javascript by ChatGPT. This type of quiz is not linked to a database unless such integration is done, so the scores are not stored. However, they make for good self-assessment for students at the end of each topic.

The quizzes are easily generated using a set of prompts that are shown below, and hosted on any static page such as github pages or uploaded as a zip file into the Student Learning Space.

The URL for this sample quiz is at https://physicstjc.github.io/sls/kinematics-quiz. In fact, this quiz can be used as a template for quantitative quizzes for other topics as well. All the user has to do is to edit the five fields in each question: the question, correct answer, unit, equation and explanation within the index.html file (right-click to save and edit with plain text editor).

The format of the questions is written in this way:

const problems = [
      {
        question: "A car starts from rest and accelerates uniformly at 2.0 m/s² for 10 seconds. What is the final velocity of the car?",
        correctAnswer: 20,
        unit: "m/s",
        equation: "v = u + at",
        explanation: "Using v = u + at, where u = 0 (starts from rest), a = 2.0 m/s², and t = 10 s, we get v = 0 + 2.0*10 = 20 m/s."
      },
      {
        question: "A car traveling at 15 m/s accelerates uniformly at 3.0 m/s² for 5.0 seconds. What is the final velocity of the car?",
        correctAnswer: 30,
        unit: "m/s",
        equation: "v = u + at",
        explanation: "Using v = u + at, where u = 15 m/s, a = 3.0 m/s², and t = 5.0 s, we get v = 15 + 3.0*5.0 = 30 m/s."
      }]

The initial prompts given to ChatGPT were:

  • Create a javascript app to explain problems involving equations of motion, v = u + at, v^2 = u^2 + 2as, s = (u + v)*t /2 and s = ut + 0.5 at^2.
  • Give a word problem based on any one of these equations.
  • Use an input box for the user to key in their answer.
  • Indicate the required unit next to the input box.
  • If the answer is wrong, explain to the user why it is wrong.
  • If the user is correct, add 1 to the score and proceed to another problem.
  • Indicate the scores over the total number of questions attempted.

The follow-up or refinement prompts were:

  • Add 10 different problems to the list.
  • Use “Previous” and “Next” buttons to navigate.
  • When the user returns to a question that was attempted previously, he should not be able to attempt that question again.
  • Add some css styling to make it appealing.
  • Randomise the appearance of the questions and do not repeat questions.
  • Represent the values in 2 significant figures.

The workflow for converting the generated codes to a web app can be found here.

Relative Velocity Simulation

0 m/s

In yet another demonstration of ChatGPT 4o’s capabilities, I generated the above simulation app without writing a single line of code myself: https://physicstjc.github.io/sls/relative-velocity/index.html

The process took 4 prompts.

Prompt 1: Create a javascript simulation in a single html file that demonstrates the addition of two velocity vectors to give a resultant velocity. The velocity of a boat travelling in still water moving across a river is shown as vertically upward. A slider will change the speed and direction of the water flow. The velocity of the river water is also shown. Finally, show the addition of the two vectors to give a third vector: the resultant velocity. Create a button for animating the boat’s movement.

Response: Here’s an HTML file with embedded JavaScript to create a simulation of the addition of two velocity vectors. This simulation includes a slider to adjust the speed and direction of the river flow, and a button to animate the boat’s movement. (Code is not included to avoid making this post too long.)

Prompt 2: Use two horizontal lines to show the shores of the river, also the starting and ending point of the boat’s journey. The boat should be represented with a pencil-like shape, moving upward from one horizontal line to another. The boat should be moving in the direction of the resultant velocity. The vectors should be represented with arrows, not just lines.

Response: Here’s the updated HTML file with the specified features:

Two horizontal lines representing the shores of the river.
A pencil-like shape representing the boat, moving from one shore to the other in the direction of the resultant velocity.
Arrows to represent the vectors.

Prompt 3: Very good! Now invert the shape of the boat vertically. Also, draw some light blue wavy curves between the two horizontal lines that are stationary when the river speed is zero but move at the river velocity otherwise.

Response: Here’s the updated HTML file with the specified changes:

The boat shape is inverted vertically.
Light blue wavy curves are drawn between the two horizontal lines to represent the river water. These waves are stationary when the river speed is zero but move at the river velocity otherwise.

Prompt 4: Keep the canvas to 640 pixels wide and 480 pixels tall. Resize everything else accordingly.

And what you see in the beginning of this post was the result.

Radioactive Decay Simulation Created Using ChatGPT 4o


This simulation of radioactive decay was created using ChatGPT4o.

The prompts used are:

  • Create a javascript simulation with a html5 canvas. Show all the codes in one page.
  • Start with grey particles in a 60 by 60 arrangement. Represent the particles using small circles.
  • Upon clicking the start animation button, every second, a number of grey particles will turn red. Randomly select the particles to decay. Assume the half-life to be one second initially. Allow the user to change the half life from one to 200 seconds. The particles that have turned red must remain red.
  • Use plotly.js to create a decay graph. The horizontal axis is time and vertical axis is number of undecayed nuclei.
  • Initialise the graph such that the time axis starts at zero and the vertical axis shows 3600 at first.
  • Refresh the particles and the graph every second.
  • Display the numerical value of time and number of undecayed particles in text as well.
  • Add a button to download the data in csv format.

Radioactive decay is a fundamental process in nuclear physics where unstable atomic nuclei lose energy by emitting radiation. This decay occurs randomly for individual atoms, but when observed in a large sample, it follows a predictable statistical pattern described by the half-life, which is the time required for half of the radioactive nuclei in a sample to decay. The half-life is a constant characteristic of each radioactive isotope and is not affected by physical conditions such as temperature or pressure.

The probability of decay for each nucleus per unit time is constant, leading to an exponential decay law. Mathematically, if $N_O$​ is the initial number of undecayed nuclei, the number remaining at time 𝑡t can be described by $N(t) = N_0 \dot (0.5)^{t/T_{1/2}}$, where $T_{1/2}$​ is the half-life. This exponential relationship explains why, after each half-life, half of the remaining radioactive atoms will have decayed. As a result, the decay process continues until all the radioactive material has transformed into stable isotopes.

In our simulation, we model this stochastic process by randomly determining whether each nucleus decays based on the given half-life. Each second, a fraction of the remaining grey particles (representing undecayed nuclei) turn red (representing decayed nuclei), mimicking the random yet statistically predictable nature of radioactive decay. The simulation and accompanying graph provide a visual and quantitative representation of how radioactive substances diminish over time, illustrating the principles of exponential decay and the role of half-life in nuclear physics.

Analogue Meter Template

This GeoGebra applet (https://www.geogebra.org/m/watavkq8) can serve as a template for an analogue meter.

I added a check for the text input so that users have to key in the correct number of decimal places according to the precision of the instrument. For instance, a reading of 1 V should be recorded as 1.00 V and 1.5 V recorded as 1.50 V. Users need to read to half the smallest division, e.g. if the needle is between 2.4 and 2.5, they should input 2.45 V.