Course: Math 2401 Differential Equations
Author: Barry McQuarrie
Last Updated: Oct 2014

Section 4.3 Undetermined Coefficients

Example

Here is the differential equation example from the lecture:

L[y_,g_]:=D[y,{t,4}]+2 D[y,{t,2}]+y==g
L[y[t],3 Sin[t]-5 Cos[t]]

Associated Homogeneous Equation

Assume a solution looks like y(t)=(e^(r t)), subsititute into the homogeneous differential equation. This leads to the characteristic equation:

L[Exp[r*t],0]

Mathematica doesn't know to cancel the (e^(r t)), but we do!

characteristic=r^4+2r^2+1==0

Solve[characteristic,r]

So we have complex conjugate solutions r=±i of multiplicity two. Since λ=0, μ=1, two solutions are (Subscript[y, 1])(t)=(e^(λ t))cos μ t, (Subscript[y, 2])(t)=(e^(λ t))sin μ t

(Subscript[y, 1])[t_]=Cos[t]
(Subscript[y, 2])[t_]=Sin[t]

Since the roots were multiplicity two, the third and fourth solutions are given by:

(Subscript[y, 3])[t_]=t (Subscript[y, 1])[t]
(Subscript[y, 4])[t_]=t (Subscript[y, 2])[t]

The complementary solution is given by

(Subscript[y, c])[t_]=(∑_(i=1)^4)(Subscript[c, i])(Subscript[y, i])[t]

Particular Solution to Nonhomogeneous Equation

Assume the particular solution has a form based on the form of g(t)=3 sin t-5 cos t:

Y[t_]=A Cos[t]+B Sin[t]

This will fail since it overlaps with the complementary solution. Multiply by t:

Y[t_]=A t Cos[t]+B t Sin[t]

This will also fail since it overlaps with the complementary solution. Multiply by t again:

Y[t_]=A t^2 Cos[t]+B t^2 Sin[t]

This has no overlap with the complementary solution, so it will work.

We want to substitute into the nonhomogeneous differential equation and simplify. Let's have Mathematica do the algebra for us:

L[Y[t],3 Sin[t]-5 Cos[t]]

Simplify[%]

From this, we see that for this equation to be true for all values of t we must have

eq1=5==8A
eq2=0==3+8B
coefficients=Solve[{eq1,eq2},{A,B}]

These equation could have been solved using Cramer's rule instead of Mathematica. Now we have for the particular solution

(Subscript[y, p])[t_]=Y[t]/.Flatten[coefficients]

General Solution to Nonhomogeneous Equation

The general solution is therefore

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

Solution to Initial Value Problem

Here are the equations we need to solve for the constants:

eq1=y[0]==0
eq2=y'[0]==1
eq3=y''[0]==2
eq4=y'''[0]==3
constants=Solve[{eq1,eq2,eq3,eq4},{(Subscript[c, 1]),(Subscript[c, 2]),(Subscript[c, 3]),(Subscript[c, 4])}]

The initial value problem has solution

(Subscript[y, IVP])[t_]=y[t]/.Flatten[constants]

Check our work

L[(Subscript[y, IVP])[t],3 Sin[t]-5 Cos[t]]//Simplify

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

Check our work

Clear[Y,y]

DSolve[{L[y[t],3 Sin[t]-5 Cos[t]],y[0]==0,y'[0]==1,y''[0]==2,y'''[0]==3},y[t],t]
Simplify[%]

Well done indeed.

Section 4.4 Variation of Parameters

Example

Here is the differential equation example from the lecture:

Clear[y]
L[y_,g_]:=D[y,{t,3}]-D[y,t]==g
L[y[t],Cos[t]^2]

Associated Homogeneous Equation

Assume a solution looks like y(t)=(e^(r t)), subsititute into the homogeneous differential equation. This leads to the characteristic equation:

L[Exp[r*t],0]

Mathematica doesn't know to cancel the (e^(r t)), but we do!

characteristic=r^3-r==0

Solve[characteristic,r]

Therefore, a fundamental set of solutions is given by

(Subscript[y, 1])[t_]=Exp[0 *t]
(Subscript[y, 2])[t_]=Exp[1*t]
(Subscript[y, 3])[t_]=Exp[-1*t]

The complementary solution is given by

(Subscript[y, c])[t_]=(∑_(i=1)^3)(Subscript[c, i])(Subscript[y, i])[t]

Particular Solution to Nonhomogeneous Equation

In this case, we can use the equations we worked out in general in class (Why? Because Barry said we could, and it would be a pain to work through the details for n>2.)

Let's work out all the Wronskian type detemrinants

g[t_]=Cos[t]^2

mat={{(Subscript[y, 1])[t],(Subscript[y, 2])[t],(Subscript[y, 3])[t]},{(Subscript[y, 1])'[t],(Subscript[y, 2])'[t],(Subscript[y, 3])'[t]},{(Subscript[y, 1])''[t],(Subscript[y, 2])''[t],(Subscript[y, 3])''[t]}};
MatrixForm[mat]
W[t_]=Det[mat]

(Subscript[mat, 1])={{0,(Subscript[y, 2])[t],(Subscript[y, 3])[t]},{0,(Subscript[y, 2])'[t],(Subscript[y, 3])'[t]},{1,(Subscript[y, 2])''[t],(Subscript[y, 3])''[t]}};
MatrixForm[(Subscript[mat, 1])]
(Subscript[W, 1])[t_]=Det[(Subscript[mat, 1])]
(∫_0^t)((g[s](Subscript[W, 1])[s])/(W[s]))\[DifferentialD]s
(Subscript[Y, 1])[t_]=(Subscript[y, 1])[t]*(∫_0^t)((g[s](Subscript[W, 1])[s])/(W[s]))\[DifferentialD]s

(Subscript[mat, 2])={{(Subscript[y, 1])[t],0,(Subscript[y, 3])[t]},{(Subscript[y, 1])'[t],0,(Subscript[y, 3])'[t]},{(Subscript[y, 1])''[t],1,(Subscript[y, 3])''[t]}};
MatrixForm[(Subscript[mat, 2])]
(Subscript[W, 2])[t_]=Det[(Subscript[mat, 2])]
(∫_0^t)((g[s](Subscript[W, 2])[s])/(W[s]))\[DifferentialD]s
(Subscript[Y, 2])[t_]=(Subscript[y, 2])[t]*(∫_0^t)((g[s](Subscript[W, 2])[s])/(W[s]))\[DifferentialD]s

(Subscript[mat, 3])={{(Subscript[y, 1])[t],(Subscript[y, 2])[t],0},{(Subscript[y, 1])'[t],(Subscript[y, 2])'[t],0},{(Subscript[y, 1])''[t],(Subscript[y, 2])''[t],1}};
MatrixForm[(Subscript[mat, 3])]
(Subscript[W, 3])[t_]=Det[(Subscript[mat, 3])]
(∫_0^t)((g[s](Subscript[W, 3])[s])/(W[s]))\[DifferentialD]s
(Subscript[Y, 3])[t_]=(Subscript[y, 3])[t]*(∫_0^t)((g[s](Subscript[W, 3])[s])/(W[s]))\[DifferentialD]s

The complete particular solution is given by

(Subscript[y, p])[t_]=(∑_(i=1)^3)(Subscript[Y, i])[t]

Simplify[%]

Eliminating the terms which overlap with the complementary solution, we are left with the following particular solution:

(Subscript[y, p])[t_]=(1/10) (-5 t-Cos[t] Sin[t])

General Solution to Nonhomogeneous Equation

The general solution is therefore

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

Check our work

First, check by substituting into the differential equation:

L[y[t],Cos[t]^2]
Simplify[%]

Second, check using Mathematica's DSolve:

Clear[y]

DSolve[L[y[t],Cos[t]^2],y[t],t]

This is our solution using the trig identity sin(2t)=2sin t cos t, and different constants.

Well done indeed.