for mi 1 lab changed

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
__author__ = 'vladimirtsvetkov'
import numpy as np
a = np.pi / 4
g = 10
v0 = 40
ro = 7600
r = 0.2
#first model(simple)
x = np.tan(a) / (g / (2 * v0 * v0 * np.cos(a) * np.cos(a)))
print 'simple model:'
print x
#second model(complex)
vx = v0 * np.cos(a)
vy = v0 * np.sin(a)
h = 0.01
b = 0.16 * 1.15 * np.pi * r * r / 2.0
m = ro * 4 * np.pi * r * r * r /3
def fvx(vx, vy):
return ((-b * vx * np.sqrt(vx*vx + vy*vy))/m)
def fvy(vx, vy):
return -g - ((b * vy * np.sqrt(vx*vx + vy*vy))/m)
y = 0
x = 0
flag = False
xprev = 0
yprev = 0
xmax = 120
while (True):
k11 = h * fvx(vx, vy)
k12 = h * fvy(vx, vy)
k21 = h * fvx(vx + h * k11/2, vy + h * k12/2)
k22 = h * fvy(vx + h * k11/2, vy + h * k12/2)
k31 = h * fvx(vx + h * k21/2, vy + h * k22/2)
k32 = h * fvy(vx + h * k21/2, vy + h * k22/2)
k41 = h * fvx(vx + h * k31, vy + h * k32)
k42 = h * fvy(vx + h * k31, vy + h * k32)
vx += (k11 + 2 * k21 + 2 * k31 + k41)/6
vy += (k12 + 2 * k22 + 2 * k32 + k42)/6
v = np.sqrt(vx*vx + vy*vy)
xprev = x
yprev = y
x += vx * h
y += vy * h
if (x == xmax):
flag = True
break
if (x > xmax):
break
if (flag):
print 'complex model1:'
print x
else:
print 'complex model2:'
print x
#print (xprev * y - x * yprev)/(y - yprev)