Reputation: 53
I have a question from school to simulate pendulum motion based on taylor series expansion.
Angular frequency d 2 θ d t 2 = − m G R I sin ( θ )
I am quite new to python. I know now how to simulate using Euler's method.
for n in range(N_t):
u[n+1] = u[n] + dt*v[n]
v[n+1] = v[n] + dt*(m*g*r/I)*sin(u[n])
How can I simulate it using taylor expansion? Should I run it the code only as below?
f′′(x0) = 2a2
Upvotes: 0
Views: 370
Reputation: 25992
In the equation u''=f(u)
you get higher order derivatives by deriving this equation by applying chain and product rule and substituting back the ODE for all second derivatives of u
. The values of u
and u'
are taken from the current state vector.
u''' = f'(u)u'
u^{(4)} = f''(u)*u'^2 + f'(u)*u''
= f''(u)*u'^2 + f'(u)*f(u)
u^{(5)} = f'''(u)*u'^3 + 3f''(u)*u'*f(u) + f'(u)^2*u'
There is also a systematic way using Taylor series arithmetics of automatic/algorithmic differentiation.
(2022/06/29) To solve x''=-sin(x)
-- the constant factors become trivial by rescaling the time -- via Taylor series anywhere, reformulate this as system
x'=y
y'=-v
u=cos(x) ==> u' = -v*y
v=sin(x) ==> v' = u*y
the last two via the trigonometric derivatives and the chain rule. Comparing coefficients left and right results in coupled incremental formulas for the coefficients of the Taylor series of all variables, with x(t0)=x0, y(t0)=y0, u(t0)=cos(x0), v(t0)=sin(x0)
.
Upvotes: 1
Reputation: 1369
I assume you meant this from your code,
I also assume that u := θ and v := θ'.
So, the Taylor expansion of sin(x) is
and your equation is now
So, you can calculate u and v from the above equation. Or, I don't know if your teacher wanted you to calculate the integrals first and then use Taylor series.
Upvotes: 0