Plotting Potential and Kinetic Energy for a falling object

458 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Scott Ausbrooks

ungelesen,
06.05.2015, 15:01:0406.05.15
an vpytho...@googlegroups.com
I have a VPython program that prints the Potential and Kinetic Energy of a ball during its fall and plots the ball's position during the fall.  I would like to change the program to where it graphs both the Potential and the Kinetic energy vs time and add the two together to plot the total energy vs time.  I can't figure out how to add the PE and KE together because one is a vector and one is a floating point.  I can't find anywhere that addresses this issue.
Any suggestions?  Thanks in advance. 


from visual import * # must import visual or vis first
from visual.graph import * # import graphing features 

ygraph = gcurve(color=color.yellow)
xgraph = gcurve(color=color.cyan)
gd = gdisplay(x=0,y=-20,width=600, height=150)
h = 20
g = 9.81
m = 25
vball = vector(0,0,0)
pball = m*vball
ball = sphere(pos=vector(0,h,0), radius = .8,color = color.cyan)
ground = box(pos=vector(0,-0.05,-10),size = (5,0.5,10),color = color.green)
deltat = .01
t = 0

while ball.pos.y>.1:
    rate(100)
    Fgrav = vector(0,-m*g,0)
    Fnet = Fgrav
    pball = pball + Fnet * deltat
    a = vector(0,-g,0)
    vball = vball + a*deltat
    ball.pos = ball.pos + vball*deltat
    PE = m*g*ball.pos
    KE = .5 * m * vball.y**2
    t = t+deltat
    ygraph.plot(pos=(t,ball.pos.y))
    xgraph.plot(pos=(t,ball.pos.x))
    #TE = PE + KE   
    print ""
    print "Fall time =",t,"PE= ",PE,"KE= ",KE#,"Total Energy =  ",TE
    print ""
    print ""


Aaron Titus

ungelesen,
06.05.2015, 16:03:2106.05.15
an vpytho...@googlegroups.com
Scott,

Is this an assignment for a course? If so, I encourage you to ask your teacher because people on this list may not want to help you with a program in case it is supposed to be done independently.

You correctly identified the bug in that you cannot add a vector and a scalar. (This violates vector algebra, thus Python gives you an error message.) Both PE and KE must be scalars.

AT

--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Scott Ausbrooks

ungelesen,
07.05.2015, 08:34:5207.05.15
an vpytho...@googlegroups.com
I am the teacher. LOL.  I teach Chemistry at a small rural high school.  I had a question about KE and PE from our Physical Science teacher and I explained to him about conservation of energy but I wanted a nice visual presentation for him to show his class.  I am dabbling in VPython and thought this would be a good example problem.  Trying to learn as I go.

--
You received this message because you are subscribed to a topic in the Google Groups "VPython-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vpython-users/nNfG9joO3-M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vpython-user...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
"The power of instruction is seldom of much efficacy except in those happy dispositions where it is almost superfluous." (Gibbon)

Aaron Titus

ungelesen,
07.05.2015, 08:54:0207.05.15
an vpytho...@googlegroups.com
Oh, I’m so sorry, Scott!  Now you know that we are wary about possibly helping students with assignments.

ball.pos is vector with x, y, z components. When calculating the PE, use

PE=m*g*ball.pos.y

Then you can graph the PE and KE by changing the plot statements to:

    ygraph.plot(pos=(t,PE))
    xgraph.plot(pos=(t,KE))

Let us know.

AT

Scott Ausbrooks

ungelesen,
07.05.2015, 09:53:5307.05.15
an vpytho...@googlegroups.com
Got it.  Thanks much.  It is working great now.  I am sure the visual will get the point across for the teacher and the students.
Scott
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten