Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python 2b.py
- T
- Type
- Tekst
- Grootte
- 2 KB (2.056 bytes)
- Gebruikte opslagruimte
- 0 bytesEigendom van
- Locatie
- Practicum 2
- Eigenaar
- Trash Panda
- Gewijzigd op
- 15 apr. 2019 door Trash Panda
- Geopend op
- 14:53 door mij
- Gemaakt op
- 18 feb. 2019
- Geen beschrijving
- Kijkers kunnen downloaden
- # -*- coding: utf-8 -*-
- """
- Created on Fri Feb 15 11:03:41 2019
- @author: olafc
- """
- import numpy as np
- import matplotlib.pyplot as plt
- x0 = 0 #Positie in meters
- t0 = 0
- t1 = 10
- dt = 0.01
- v0 = 10 #Snelheid in meters per seconde
- P = 10 #Kracht in N
- m = 200 #Massa in kilogram
- t = np.linspace(t0, t1, int(1+t1/dt)) #Tijd range
- def Accelaration(v):
- a = -10*v**3/m
- return a
- #integrate 10=>v (v dv)= 0=>s (-10v^3/200 ds)
- #integrate 10=>v (dv/v^2)= 0=>s (-10/200 ds)
- # 10=>v [-1/v] = 0=>s [-s/20]
- # -1/v - -1/10 = -s/20
- # -1/v + 1/10 = -s/20
- # s/20 + 1/10 = 1/v
- # s+2 = 20/v
- # v(s+2) = 20
- # v = 20/(s+2)
- # ds = v dt
- # 0=>s ds = 0=>8 20/(s+2) dt
- # 0=>s (s+2)ds = 0=>8 20dt
- # 0=>s [.5s^2+2s] = 0=>8 [20t]
- # 0.5s^2+2s-160 = 0
- # volgens abc-formule s=16
- # v = 20/18
- # v = 10/9
- # v at t=8 =10/9
- # s at t=8 =16
- Pos_num = np.zeros(len(t))
- Speed_num = np.zeros(len(t))
- Pos_num[0] = 0
- Speed_num[0] = v0
- for n in range(1, len(t)):
- a = Accelaration(Speed_num[n-1])
- Speed_num[n] = Speed_num[n-1]+a*dt
- Pos_num[n] = Pos_num[n-1] + Speed_num[n-1]*dt
- c1 = np.interp(1000, t , Speed_num) #Speed bij t=10
- print("v bij t=10: ",np.round(c1,3),"m/s")
- c2 = Pos_num[800] #Positie bij t=8
- print("x bij t=8: ",np.round(c2,3),"m")
- c3 = (16-Pos_num[800]) #error bij t=8 met dt=0.01
- print("error bij t=8 met stap dt=0.01:",np.round(c3*10**3,3),"mm")
- dt = 1e-4
- t = np.linspace(t0, t1, int(1+t1/dt))
- Pos_num = np.zeros(len(t))
- Speed_num = np.zeros(len(t))
- Pos_num[0] = 0
- Speed_num[0] = v0
- for n in range(1, len(t)):
- a = Accelaration(Speed_num[n-1])
- Speed_num[n] = Speed_num[n-1]+a*dt
- Pos_num[n] = Pos_num[n-1] + Speed_num[n-1]*dt
- c4 = (16-Pos_num[80000]) #error bij t=8 met dt=1e-4
- print("error bij t=8 met stap dt=1e-4:",np.round(c4*10**3,3),"mm")
- plt.plot(t,Speed_num, "y--")
- plt.plot(t,Pos_num, "r")
- plt.plot(Pos_num, Speed_num, "g")
- plt.show
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement