> restart; 1; read
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1
>
>
#----------------------------------------------------
# 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);
`+`(diff(diff(x(t), t), t), x(t)) = `+`(`-`(`*`(`/`(1, 2), `*`(t, `*`(sin(t))))))
>
#----------------------------------------------------
# ...and its homogeneous counterpart
#----------------------------------------------------
> ode_h:=diff(x(t),t$2)+x(t);
`+`(diff(diff(x(t), t), t), x(t))
>
#----------------------------------------------------
# Solve the bloody thing using maple
#----------------------------------------------------
> dsolve(ode,x(t));
x(t) = `+`(`*`(sin(t), `*`(_C2)), `*`(cos(t), `*`(_C1)), `-`(`*`(`/`(1, 8), `*`(t, `*`(`+`(`-`(`*`(cos(t), `*`(t))), sin(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);
`*`(A, `*`(t, `*`(sin(t))))
> eval(subs(x(t)=x_p,ode_h));
`+`(`*`(2, `*`(A, `*`(cos(t)))))
> eval(subs(x(t)=x_p,ode));
`+`(`*`(2, `*`(A, `*`(cos(t))))) = `+`(`-`(`*`(`/`(1, 2), `*`(t, `*`(sin(t))))))
>
>
>
#----------------------------------------------------
# ... 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);
`+`(`*`(A, `*`(t, `*`(sin(t)))), `*`(B, `*`(t, `*`(cos(t)))))
> eval(subs(x(t)=x_p,ode_h));
`+`(`*`(2, `*`(A, `*`(cos(t)))), `-`(`*`(2, `*`(B, `*`(sin(t))))))
> eval(subs(x(t)=x_p,ode));
`+`(`*`(2, `*`(A, `*`(cos(t)))), `-`(`*`(2, `*`(B, `*`(sin(t)))))) = `+`(`-`(`*`(`/`(1, 2), `*`(t, `*`(sin(t))))))
>
>
>
#----------------------------------------------------
# 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);
`+`(`*`(A, `*`(t, `*`(sin(t)))), `*`(B, `*`(`^`(t, 2), `*`(cos(t)))))
> eval(subs(x(t)=x_p,ode_h));
`+`(`*`(2, `*`(A, `*`(cos(t)))), `*`(2, `*`(B, `*`(cos(t)))), `-`(`*`(4, `*`(B, `*`(t, `*`(sin(t)))))))
> eval(subs(x(t)=x_p,ode));
`+`(`*`(2, `*`(A, `*`(cos(t)))), `*`(2, `*`(B, `*`(cos(t)))), `-`(`*`(4, `*`(B, `*`(t, `*`(sin(t))))))) = `+`(`-`(`*`(`/`(1, 2), `*`(t, `*`(sin(t))))))
>
>
#----------------------------------------------------
# ...and this works for B=1/8 and A=-B
#----------------------------------------------------
> subs(A=-1/8,B=1/8,eval(subs(x(t)=x_p,ode)));
`+`(`-`(`*`(`/`(1, 2), `*`(t, `*`(sin(t)))))) = `+`(`-`(`*`(`/`(1, 2), `*`(t, `*`(sin(t))))))
>
 

>