Section 3.5: Mathematica Addition Lecture

Example 8y''+8y'+2y =  (e^(-2t))+t cos(2 t), using Mathematica to assist with the details.

Clear[y,Y,A1,A2,A3,A4,eq2]

We worked the complementary solution out by hand (remember, it is the solution to the associated homogeneous equation)

(Subscript[y, c])[t_]=c1*Exp[-t/2]+c2*t*Exp[-t/2]

Here is the assumed form of the particular solution we chose, substituted into the DE and simplified:

Y[t_]=B1 (E^(-2 t))+B2 Cos[2 t]+B3 t Cos[2 t]+B4 Sin[2 t]+B5 t Sin[2 t]

eq2=Simplify[8Y''[t]+8Y'[t]+2Y[t]==Exp[-2t]+t*Cos[2t]]

This is doing a lot of mundane computation for you! We want coefficients of the different functions of t (the same ones we had in Y(t)). We can do it by hand, or use Mathematica to simplify a little bit first.

Collect[eq2,{Exp[-2t],Cos[2*t],Sin[2*t]}]

Setting the coefficients of different functions of t to zero will make the result true for any value of t.

This gives you the system of equations the coefficients must satisfy.

You can use Mathematica to solve the equations for you.

eq1=1-18 B1==0
eq2=30 B2-8 B3-16 B4-32 B5 ==0
eq3=1+30 B3 -16 B5  ==0
eq4=16 B2+32 B3+30 B4-8 B5 ==0
eq5=16 B3 +30 B5  ==0
sol=Solve[{eq1,eq2,eq3,eq4,eq5},{B1,B2,B3,B4,B5}]

So, we can define a particular solution:

(Subscript[y, p])[t_]=B1 (E^(-2 t))+B2 Cos[2 t]+B3 t Cos[2 t]+B4 Sin[2 t]+B5 t Sin[2 t]/.sol[[1]]

The general solution to the nonhomogeneous DE is

(Subscript[y, general])[t_]=(Subscript[y, c])[t]+(Subscript[y, p])[t]

Let's check the solution we found is correct by subsituting back into the orginal nonhomogeneous DE:

Simplify[8(Subscript[y, general])''[t]+8(Subscript[y, general])'[t]+2(Subscript[y, general])[t]==Exp[-2t]+t*Cos[2*t]]

Let's solve the initial value problem using Mathematica to get the derivative and solve the system of equations:

eq1=(Subscript[y, general])[0]==0
eq2=(Subscript[y, general])'[0]==0
solb=Solve[{eq1,eq2},{c1,c2}]

(Subscript[y, IVP])[t_]=(Subscript[y, general])[t]/.solb[[1]]

Check our solution to the IVP:

Simplify[(Subscript[y, IVP])[0]]
Simplify[(Subscript[y, IVP])'[0]]

Now, we can plot it, analyze it, do whatever we like:

sol=Plot[(Subscript[y, IVP])[t],{t,0,15},PlotStyle->{Thick},AxesLabel->{"t","y"}]

Some things to note : There are lots of decaying exponentials whose contribution diminishes as time increases, and the solution approaches the curve:

((94 Cos[2 t])/4913)-(15/578) t Cos[2 t]+((104 Sin[2 t])/4913)+(4/289) t Sin[2 t]

The solution is growing due to the t in the  t cos(2t) term in g(t).

Plot[{(Subscript[y, IVP])[t],((94 Cos[2 t])/4913)-(15/578) t Cos[2 t]+((104 Sin[2 t])/4913)+(4/289) t Sin[2 t]},{t,0,10},PlotStyle->{Thick},AxesLabel->{"t","y"}]

Example y''+y=(t^2)cos t

We did the foundation work in class to get the form for Y(t). Now let's use Mathematica to assist with the simplification.

Sub into the DE:

L[y_]:=D[y,{t,2}]+y
Y=B1 t^3 Cos[t] + B2 t^2 Cos[t] + B3 t Cos[t] + B4 t^3 Sin[t] + B5 t^2 Sin[t] + B6 t Sin[t]
eq=L[Y]==t^2 Cos[t]

Collect the coefficients of different functions of t, and solve for the coefficients:

eq1=2B2+2B6==0
eq2=6B1+4B5==0
eq3=6B4==1
eq4=-2B3+2B5==0
eq5=-4B2+6B4==0
eq6=-6B1==0
sol=Solve[{eq1,eq2,eq3,eq4,eq5,eq6},{B1,B2,B3,B4,B5,B6}]

Let's get the Mathematica solution to see if we got it right:

DSolve[y''[t]+y[t]==t^2 Cos[t],y[t],t]
Simplify[%]

Notice that Mathematica includes a -1/8 cos t in the Y(t), but that can be collected together with the C[1] cos t part.

Example u''+((Subscript[w, 0])^2)u = cos((Subscript[w, 0])t) (e^t)(on handout)

U[t_]=A Exp[t] Cos[w0 t]+B Exp[t] Sin[w0 t]
Simplify[U''[t]+w0^2 U[t]]

This is doing a lot of heavy lifting for you! You can see this by looking at the derivatives:

U'[t]
U''[t]

Let's check the solution we found:

DSolve[y''[t]+w0^2 y[t]==Cos[w0*t] Exp[t],y[t],t]

Simplify[%]

This is the general solution, but we were told to find a particular solution. We can get the particular solution from the general solution by setting the constants to zero:

%/.C[1]->0/.C[2]->0

Which agrees with what we found.

Remember, you can always check your work by substituting your solution back into the differential equation.