0

I have tried adapting euler method code, and am using euler to calculate the first value so there are two for me to use in verlet but when i plot the graph i just get two perpendicular straight lines.

this is the code:

for t in t_array:

    if t == 0:
        x0 = x
        x1 = x0
        a = -k * x1 / m
        x2 = x1 + dt * v
        v = v + dt * a
        x_list.append(x2)
        v_list.append(v)
    else:
        x2 = x1
        x1 = x0
        x2 = 2*x1 - x0 + dt**2*a
        v = (1/dt)*(x2 - x1)
        x_list.append(x2)
        v_list.append(v)

and then i plot a graph using matplotlib.

Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
Soph44
  • 1
  • Can you post some code that will run? In particular, you never initialize your x and v lists, and it would be helpful to see what you're doing to plot it. – David Sep 03 '20 at 20:51
  • If one follows the assignments one finds that the computed values are never used, everything is filled with x0. What was probably intended was `x0,x1 = x1,x2`. – Lutz Lehmann Feb 28 '21 at 07:09

0 Answers0