May-29-2020, 02:50 PM
I am pretty new in Python. I have a working code which looks like
time value of y
0.0 0.0
1.0 2.91774937823
2.0 5.82044363971
3.0 8.69348861202
4.0 11.5231772897
5.0 14.297051396
Now I want to use a value in time t = 5 (y = 14.297051396) as my initial condition and find values of y in time t = 6, ..., 16 for k=1.1. How should I change my code?
I tried this code
What did I do wrong? Could somebody explain to me, how to change it? (I am self-learner in Python and I do not study programming).
import numpy as np import scipy.integrate as sp import sys g, l, k = 9.81, 10, float(input()) PTS = 6 def rhs( y, t, g, l, k ): return [ k*t/l * np.cos(y[1]) - g/l * np.sin(y[1]),y[0] ] y0 = [ 0, 0 ] t = np.linspace( 0, 6, PTS+1 ) y = sp.odeint( rhs, y0, t, args = (g, l, k) ) for i in range(PTS): print( t[i], np.arctan(k*t[i]/g) *180/np.pi )where you have to write a value 0.5 (it is value of "k"). The output of this code is:
time value of y
0.0 0.0
1.0 2.91774937823
2.0 5.82044363971
3.0 8.69348861202
4.0 11.5231772897
5.0 14.297051396
Now I want to use a value in time t = 5 (y = 14.297051396) as my initial condition and find values of y in time t = 6, ..., 16 for k=1.1. How should I change my code?
I tried this code
import numpy as np import scipy.integrate as sp import sys g, l, k = 9.81, 10, float(input()) PTS = 12 def rhs( y, t, g, l, k ): return [ k*t/l * np.cos(y[1]) - g/l * np.sin(y[1]), y[0] ] y0 = [ 14.297051396, 5 ] t = np.linspace( 5, 17, PTS+1 ) y = sp.odeint( rhs, y0, t, args = (g, l, k) ) for i in range(PTS): print( t[i], np.arctan(k*t[i]/g) *180/np.pi )and write 1.1, but the output is the same as in the case that I write y0 = [ 0, 0 ].
What did I do wrong? Could somebody explain to me, how to change it? (I am self-learner in Python and I do not study programming).