About vpython for non-linear pendulum problem

30 Views Asked by At

What is the problem with damped solution, what do I need to change, do I have a definition error?Or is the mathematical model wrong?

from vpython import sphere, cylinder, color, rate, vector, gcurve, canvas, graph

# set up the curve objects for the plots
anglecurve = gcurve(graph=graph1, color=color.cyan)          # a graphics curve for the angular displacement
velcurve = gcurve(graph=graph1, color=color.red)             # a graphics curve for the angular velocity
phasecurvedamp = gcurve(graph=graph2, color=color.magenta)   # a graphics phase space curve for the damped pendulum
phasecurveundamp = gcurve(graph=graph2, color=color.green)   # a graphics phase space curve for the undamped pendulum


### Run the animation ###

# Loop over the solutions calculated 
for i in range(0,N):
    
    angle = rsol[0,i]         # undamped solution
    angle_d = rsol_damp[0,i]  # damped solution
    
    
    rod.axis = vector(L*np.sin(angle), -L*np.cos(angle), 0) 
    bob.pos = vector(L*np.sin(angle), -L*np.cos(angle), 0)   
    
    # update damped system
    rod_d.axis = vector(L*np.sin(angle_d), -L*np.cos(angle_d), 0)   
    bob_d.pos = vector(L*np.sin(angle_d), -L*np.cos(angle_d), 0)    
    

   
    
    tpoint = i * tend / N   # scale the t-component manually
    
    # update graph of angular displacement against time
#    anglecurve.plot(tpoint, rsol[0,i])      # undamped system
    anglecurve.plot(tpoint, rsol_damp[0,i]) # damped system
    
    
#    velcurve.plot(tpoint, rsol[1,i])      # undamped system
    velcurve.plot(tpoint, rsol_damp[1,i]) # damped system

    # update graph of phase space
    phasecurveundamp.plot(rsol[0,i], rsol[1,i])           # undamped system
    phasecurvedamp.plot(rsol_damp[0,i], rsol_damp[1,i])   # damped system
    
    
    rate(50)   # framerate for all windows
    
print("End")

An error occurred:Unexpected token punc «,», expected punc «]» at line 55: angle = rsol[0,i]

0

There are 0 best solutions below