# # Maple's "subs" and "solve" commands are used to find the "particular" # solution to non-homogeneous 2nd order ODEs # # Nonhomogeneous equations and Maple. First note that Maple's # dsolve numeric option is indifferent to whether or not the DE is # homogeneous, or, for that matter, even linear. So if all one wants is # numerical solutions, they come easily. > linop1:=diff(y(t),t$2)+t*diff(y(t),t)+t^2*y(t); / 2 \ | d | / d \ 2 linop1 := |----- y(t)| + t |---- y(t)| + t y(t) | 2 | \ dt / \ dt / -------------------------------------------------------------------------------- > inits10:=y(0)=1,D(y)(0)=0; inits10 := y(0) = 1, D(y)(0) = 0 -------------------------------------------------------------------------------- > hgsoln1:=dsolve({linop1,inits10},y(t),numeric); hgsoln1 := proc(rkf45_x) ... end -------------------------------------------------------------------------------- > hgsoln1(1); d [t = 1, y(t) = .9279347656982888, ---- y(t) = -.2656732748739848] dt -------------------------------------------------------------------------------- > curve1pts:=[seq([.1*k,rhs(hgsoln1(.1*k)[2])],k=1..50)]: -------------------------------------------------------------------------------- > p1:=plot(curve1pts): -------------------------------------------------------------------------------- > with(plots):display(p1); > ** Maple V Graphics ** -------------------------------------------------------------------------------- > inits01:=y(0)=0,D(y)(0)=1;hgsoln2:=dsolve({linop1,inits01},y(t),numeric); inits01 := y(0) = 0, D(y)(0) = 1 hgsoln2 := proc(rkf45_x) ... end -------------------------------------------------------------------------------- > curve2ps:=[seq([.1*k,rhs(hgsoln2(.1*k)[2])],k=1..50)]: -------------------------------------------------------------------------------- > p2:=plot(curve2ps):display({p1,p2}); -------------------------------------------------------------------------------- > > ** Maple V Graphics ** -------------------------------------------------------------------------------- # Getting closed-form solutions can be harder, and in many cases # impossible with or without computer assistance. One reasonably # broad class of cases for which closed-form solutions are available is # this: # If the coefficients of the lhs of the DE are constants, and if the rhs of # the DE is a polynomial*(constant or exp(constant*t) or # sin(constant*t) or cos(constant*t)) or a sum of this type, there is a # closed form solution. # You get it by guessing that the solution is a function of the same type # as the rhs, with possibly a couple of factors of t thrown in. > linop2:=diff(y(t),t$2)+2*diff(y(t),t)+2*y(t); / 2 \ | d | / d \ linop2 := |----- y(t)| + 2 |---- y(t)| + 2 y(t) | 2 | \ dt / \ dt / -------------------------------------------------------------------------------- > rhs2:=t^3+t+1; 3 rhs2 := t + t + 1 -------------------------------------------------------------------------------- > tryit:=subs(y(t)=a*t^3+b*t^2+c*t+d,linop2=rhs2); / 2 \ | d 3 2 | / d 3 2 \ tryit := |----- (a t + b t + c t + d)| + 2 |---- (a t + b t + c t + d)| | 2 | \ dt / \ dt / 3 2 3 + 2 a t + 2 b t + 2 c t + 2 d = t + t + 1 -------------------------------------------------------------------------------- > solve(identity(tryit,t),{a,b,c,d}); {c = 2, d = 0, b = -3/2, a = 1/2} -------------------------------------------------------------------------------- > ans:=subs(",a*t^3+b*t^2+c*t+d); 3 2 ans := 1/2 t - 3/2 t + 2 t -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- > subs(y(t)=ans,linop2); / 2 \ | d 3 2 | / d 3 2 \ 3 2 |----- (1/2 t - 3/2 t + 2 t)| + 2 |---- (1/2 t - 3/2 t + 2 t)| + t - 3 t | 2 | \ dt / \ dt / + 4 t -------------------------------------------------------------------------------- > expand("); 3 t + t + 1 -------------------------------------------------------------------------------- > rhs3:=sin(t); rhs3 := sin(t) -------------------------------------------------------------------------------- > tryit3:=subs(y(t)=a*sin(t)+b*cos(t),linop2=rhs3);sn:=solve(identity(tryit3,t),{a,b});ans:=subs(sn,a*sin(t)+b*cos(t)); / 2 \ | d | / d \ tryit3 := |----- (a sin(t) + b cos(t))| + 2 |---- (a sin(t) + b cos(t))| | 2 | \ dt / \ dt / + 2 a sin(t) + 2 b cos(t) = sin(t) sn := {a = 1/5, b = -2/5} ans := 1/5 sin(t) - 2/5 cos(t) -------------------------------------------------------------------------------- > expand(subs(y(t)=ans,linop2)); sin(t) -------------------------------------------------------------------------------- > rhs4:=exp(-t)*sin(t); rhs4 := exp(- t) sin(t) -------------------------------------------------------------------------------- > tryit4:=subs(y(t)=a*exp(-t)*sin(t)+b*exp(-t)*cos(t),linop2=rhs4); / 2 \ | d | tryit4 := |----- (a exp(- t) sin(t) + b exp(- t) cos(t))| | 2 | \ dt / / d \ + 2 |---- (a exp(- t) sin(t) + b exp(- t) cos(t))| + 2 a exp(- t) sin(t) \ dt / + 2 b exp(- t) cos(t) = exp(- t) sin(t) -------------------------------------------------------------------------------- > sn4:=solve(identity(tryit4,t),{a,b});ans:=subs(sn4,a*exp(-t)*sin(t)+b*exp(-t)*cos(t)); sn4 := ans := a exp(- t) sin(t) + b exp(- t) cos(t) -------------------------------------------------------------------------------- > tryit4b:=subs(y(t)=a*t*exp(-t)*sin(t)+b*t*exp(-t)*cos(t),linop2=rhs4);sn4b:=solve(identity(tryit4b,t),{a,b});ans:=subs(sn4b,a*exp(-t)*t*sin(t)+b*t*exp(-t)*cos(t)); / 2 \ | d | tryit4b := |----- (a t exp(- t) sin(t) + b t exp(- t) cos(t))| | 2 | \ dt / / d \ + 2 |---- (a t exp(- t) sin(t) + b t exp(- t) cos(t))| \ dt / + 2 a t exp(- t) sin(t) + 2 b t exp(- t) cos(t) = exp(- t) sin(t) sn4b := {a = 0, b = -1/2} ans := - 1/2 t exp(- t) cos(t) -------------------------------------------------------------------------------- > --------------------------------------------------------------------------------