Fysik 1/Logbog uge 39

Fra Meinertz Wiki

Skift til: Navigation, Søgning

Gruppemedlemmer:

fra laboratoriehold theta

I dag har vi lært at bruge VPython. Vi fik forholdsvis hurtigt lavet et program, der simulerede en bold, der falder i parabel under tyngdeaccelerationen. Vi fik programmet til at tegne projektilbanen samt en vektor for impuls, der fulgte bolden.

Herefter modificerede vi eksempelfilen til at inkludere en vinkelhastighedsvektor vha. krydsproduktet.

Her er vores program (VPythonHelloWorld.py):

from visual import *
autoscale=0
x=5
scene.range=(x,x,x)

print 'Hello World!'

mass1=sphere(pos=(0.0,2.0,0.0),radius=0.5,color=color.red)
mass1.mass=0.1
mass1.velocity=vector(10,0,0)
g=vector(0,-9.82,0)
a=0
path=curve(radius=0.05)

retning=arrow(color=color.blue,shaftwidth=0.05)
arrowtails="atorigin"

dt=0.01
t=0
while t<20:
    rate(20)
    mass1.velocity=g*t+mass1.velocity
    mass1.pos=mass1.pos+mass1.velocity*dt
    path.append(pos=mass1.pos)
    retning.pos=mass1.pos
    retning.axis=mass1.velocity*mass1.mass
    t=t+dt

Og vores modificerede version af Ian Beardens program (ModifiedCircularMotion.py):

from visual import *

t = 0
dt=0.01
w=1.0
arrowtails="atorigin"
scene.range=(3,3,3)

particle=sphere(radius=0.17,color=color.yellow)
rvec=arrow(color=color.blue,shaftwidth=0.1)
vvec=arrow(color=color.green,shaftwidth=0.1)
avec=arrow(color=color.red,shaftwidth=0.11)
path=curve(radius=0.04)
rlabel=label(pos=(0,-1.0,0), text='position', xoffset=0, yoffset=-12,
         height=15, border=10,box=0)
vlabel=label(pos=(0,-1.0,0), text='velocity', xoffset=0, yoffset=-42,
         height=15, border=10,box=0)
alabel=label(pos=(0,-1.0,0), text='acceleration', xoffset=0, yoffset=-72,
         height=15, border=10,box=0)

omega=arrow(color=color.yellow,shaftwidth=0.1)

while t<100:
    rate(100)
    if scene.kb.keys:
        s=scene.kb.getkey()
        if s=="up": w=w+0.2
        if s=="down": w=w-0.2
        if s=="left":arrowtails="atorigin"
        if s=="right":arrowtails="onparticle"
        if s=="p":dt=0
        if s=="g":dt=0.01

    r=vector(sin(w*t),cos(w*t))
    v=vector(w*cos(w*t),-w*sin(w*t))
    a=vector(-w**2*sin(w*t),-w**2*cos(w*t))
    particle.pos=r
    omega.axis=cross(r,v)/mag(r)**2

    rvec.axis=r
    vvec.axis=v
    avec.axis=a
    
    
    rlabel.text="r = ("+str(r.x)+") i + ("+str(r.y)+") j"
    vlabel.text="v = ("+str(v.x)+") i + ("+str(v.y)+") j"
    alabel.text="a = ("+str(a.x)+") i + ("+str(a.y)+") j"
    if arrowtails=="onparticle":
        vvec.pos=r
        avec.pos=r
    if arrowtails=="atorigin":
        vvec.pos=(0,0)
        avec.pos=(0,0)
    path.append(pos=r)
    t=t+dt
# -*- coding: utf-8 -*-
from visual import *
from random import gauss

ball=sphere(pos=(0,0,0),radius=0.05,color=color.blue)

arrowtails="atorigin"
#avec=arrow(color=color.green,shaftwidth=0.1)
#vvec=arrow(color=color.yellow,shaftwidth=0.3)
ball.mass=5

ball.acceleration=vector(0,-9.82,0)
path=curve(radius=0.01,color=color.red)
autoscale=1 #this off auto scaling!
scene.range=(2,1,2) #gives the property range to the scene object
scene.center=(1.5,0,0)
dt=0.0002 #dt is delta t and is 0.1 second if we are using MKS
#loop for 5 seconds:

throws = 25 #hvor mange gange der skal kastes
thrown = 0 # hvor mange gange der er kastet

# til statistik
gennemsnit = 2.768
intervaller = 

while thrown < throws:
    
    ball.pos = (0,0,0)
    ball.velocity=vector(gauss(3.71,0.134),gauss(3.71,0.134),0)

    thrown += 1
    t=0 #start at time 0
    
    while ball.pos.y >= 0:
        #rate(1000) #slows animation by 1/arg seconds
        ball.velocity = ball.velocity+ball.acceleration*dt
        ball.pos=ball.pos+ball.velocity*dt
        t=t+dt
        path.append(pos=ball.pos)
        #avec.axis=ball.acceleration
        #vvec.axis=ball.velocity
        #if arrowtails=="onball":
        #    avec.pos=ball.acceleration
        #    vvec.pos=ball.vel
        #if arrowtails=="atorigin":
        #    avec.pos=ball.pos
        #    vvec.pos=ball.pos

    print "----"
    print thrown
    print t
    print ball.pos.x

    totlen += ball.pos.x
Personlige værktøjer
Navnerum
Varianter
Handlinger
jonas.meinertz.org
Wiki
Værktøjer