> |
>
> #---------------------------------------------------- # The ODE (second order correction for weakly damped # mass spring damper system) #---------------------------------------------------- > ode:=diff(x(t),t$2)+x(t)=-1/2*t*sin(t); |
|
>
#---------------------------------------------------- # ...and its homogeneous counterpart #---------------------------------------------------- > ode_h:=diff(x(t),t$2)+x(t); |
|
>
#---------------------------------------------------- # Solve the bloody thing using maple #---------------------------------------------------- > dsolve(ode,x(t)); |
|
>
> #---------------------------------------------------- # Now do it "by hand". #---------------------------------------------------- > #---------------------------------------------------- # Here's the straightforward ansatz: multiple of rhs # is not a solution of the homogeneous ODE, but creates # a new linearly independent function: cos(t). #---------------------------------------------------- > x_p:=A*t*sin(t); |
|
> eval(subs(x(t)=x_p,ode_h)); | |
> eval(subs(x(t)=x_p,ode)); | |
>
> > #---------------------------------------------------- # ... so we should add cos(t), but this won't work # because it solves the homogeneous ODE, so multiply # by t first and then add: #---------------------------------------------------- > x_p:=A*t*sin(t)+B*t*cos(t); |
|
> eval(subs(x(t)=x_p,ode_h)); | |
> eval(subs(x(t)=x_p,ode)); | |
>
> > #---------------------------------------------------- # Of course, that now simply produces sin(t), which # we ought to add to the ansatz. But it's a solution # of the homogeneous ODE, so multiply by t and then # add. But, hang on, that's what we started with. # AAAARGH. # # Solution: Need to increase the power of t: #---------------------------------------------------- > x_p:=A*t*sin(t)+B*t^2*cos(t); |
|
> eval(subs(x(t)=x_p,ode_h)); | |
> eval(subs(x(t)=x_p,ode)); | |
>
> #---------------------------------------------------- # ...and this works for B=1/8 and A=-B #---------------------------------------------------- > subs(A=-1/8,B=1/8,eval(subs(x(t)=x_p,ode))); |
|
> |
> |