Tetrapod Project
calculate_polynomials.py
Go to the documentation of this file.
1 from numpy.lib.scimath import sqrt
2 from numpy.lib.type_check import isreal
3 from numpy.lib.ufunclike import isposinf
4 import numpy.polynomial as poly
5 import numpy as np
6 import matplotlib.pyplot as plt
7 
8 Ttot = 2
9 amax = 4
10 Vrob = 1
11 dtot = 2
12 
13 Tr_poly_coeffs = (-dtot -Ttot*Vrob, (2/3)*amax*Ttot, -4/3 + (8/9 - 4/15)*amax)
14 
15 Tr_list = poly.Polynomial(Tr_poly_coeffs).roots()
16 
17 print(Tr_poly_coeffs)
18 print(poly.Polynomial(Tr_poly_coeffs).coef)
19 
20 print(Tr_list)
21 print(Tr_list[isreal(Tr_list)*(Tr_list>=0)])
22 Tr = Tr_list[isreal(Tr_list)*(Tr_list>=0)][0]
23 
24 Th = Ttot - 2*Tr
25 
26 a = -(2/3)*amax/(Tr**3)
27 b = (4/3)*amax/Tr
28 c = -Vrob
29 
30 coeffs = (c, 0, b, 0, a)
31 
32 t1 = np.linspace(0, Tr, 50)
33 t2 = np.linspace(Tr, Tr + Th, 100)
34 t3 = np.linspace(Tr + Th, Ttot, 50)
35 f = poly.Polynomial(coeffs)
36 f_int = f.integ()
37 x1 = f(t1)
38 x2 = np.array([f(Tr)]*t2.shape[0])
39 x3 = f(-t3 + Ttot)
40 
41 t = np.concatenate((t1, t2, t3))
42 x = np.concatenate((x1, x2, x3))
43 print(t)
44 print(t.shape)
45 print(x.shape)
46 
47 print(Tr)
48 print(Tr**2)
49 
50 plt.plot(t, x)
51 plt.show()