Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.29 KB | None | 0 0
  1. Python 2b.py
  2. T
  3. Type
  4. Tekst
  5. Grootte
  6. 2 KB (2.056 bytes)
  7. Gebruikte opslagruimte
  8. 0 bytesEigendom van
  9. Locatie
  10. Practicum 2
  11. Eigenaar
  12. Trash Panda
  13. Gewijzigd op
  14. 15 apr. 2019 door Trash Panda
  15. Geopend op
  16. 14:53 door mij
  17. Gemaakt op
  18. 18 feb. 2019
  19. Geen beschrijving
  20. Kijkers kunnen downloaden
  21. # -*- coding: utf-8 -*-
  22. """
  23. Created on Fri Feb 15 11:03:41 2019
  24.  
  25. @author: olafc
  26. """
  27. import numpy as np
  28. import matplotlib.pyplot as plt
  29.  
  30.  
  31. x0 = 0          #Positie in meters
  32. t0 = 0
  33. t1 = 10
  34. dt = 0.01
  35. v0 = 10         #Snelheid in meters per seconde
  36. P = 10          #Kracht in N
  37. m = 200         #Massa in kilogram
  38. t = np.linspace(t0, t1, int(1+t1/dt)) #Tijd range
  39. def Accelaration(v):
  40.     a = -10*v**3/m
  41.     return a
  42.  
  43. #integrate 10=>v (v dv)= 0=>s (-10v^3/200 ds)
  44. #integrate 10=>v (dv/v^2)= 0=>s (-10/200 ds)
  45. # 10=>v [-1/v] = 0=>s [-s/20]
  46. # -1/v - -1/10 = -s/20
  47. # -1/v + 1/10 = -s/20
  48. # s/20 + 1/10 = 1/v
  49. # s+2 = 20/v
  50. # v(s+2) = 20
  51. # v = 20/(s+2)
  52. # ds = v dt
  53. # 0=>s ds = 0=>8 20/(s+2) dt
  54. # 0=>s (s+2)ds = 0=>8 20dt
  55. # 0=>s [.5s^2+2s] = 0=>8 [20t]
  56. # 0.5s^2+2s-160 = 0
  57. # volgens abc-formule s=16
  58. # v = 20/18
  59. # v = 10/9
  60. # v at t=8 =10/9
  61. # s at t=8 =16
  62.  
  63. Pos_num = np.zeros(len(t))
  64. Speed_num = np.zeros(len(t))
  65. Pos_num[0] = 0
  66. Speed_num[0] = v0
  67.  
  68. for n in range(1, len(t)):
  69.     a = Accelaration(Speed_num[n-1])
  70.     Speed_num[n] = Speed_num[n-1]+a*dt
  71.     Pos_num[n] = Pos_num[n-1] + Speed_num[n-1]*dt
  72.  
  73. c1 = np.interp(1000, t , Speed_num) #Speed bij t=10
  74. print("v bij t=10:                    ",np.round(c1,3),"m/s")
  75. c2 = Pos_num[800]                   #Positie bij t=8
  76. print("x bij t=8:                     ",np.round(c2,3),"m")
  77. c3 = (16-Pos_num[800])              #error bij t=8 met dt=0.01
  78. print("error bij t=8 met stap dt=0.01:",np.round(c3*10**3,3),"mm")
  79.  
  80. dt = 1e-4
  81. t = np.linspace(t0, t1, int(1+t1/dt))
  82.  
  83. Pos_num = np.zeros(len(t))
  84. Speed_num = np.zeros(len(t))
  85.  
  86. Pos_num[0] = 0
  87. Speed_num[0] = v0
  88.  
  89. for n in range(1, len(t)):
  90.     a = Accelaration(Speed_num[n-1])
  91.     Speed_num[n] = Speed_num[n-1]+a*dt
  92.     Pos_num[n] = Pos_num[n-1] + Speed_num[n-1]*dt
  93.  
  94. c4 = (16-Pos_num[80000])            #error bij t=8 met dt=1e-4
  95. print("error bij t=8 met stap dt=1e-4:",np.round(c4*10**3,3),"mm")
  96.  
  97. plt.plot(t,Speed_num, "y--")
  98. plt.plot(t,Pos_num, "r")
  99. plt.plot(Pos_num, Speed_num, "g")
  100. plt.show
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement