MATH 302-010
Ordinary Differential Equations
Prof. D. A. Edwards
Copyright 2024

More on ODEs

We begin with our standard command:

Quit[]

Repeated Roots

Mathematica has no problem handling the problem of repeated roots, whether they are real...

eqrep=y''[t]+4*y'[t]+4*y[t]==0
DSolve[eqrep,y[t],t]

or complex:

eqrep2=D[y[t],{t,4}]+4*D[y[t],{t,3}]+10*y''[t]+12*y'[t]+9*y[t]==0
DSolve[eqrep2,y[t],t]

Exercise

Write the solution of (((d^4)y)/(dt^4))+4(((d^3)y)/(dt^3))+14y''+20y'+25y=0, y(0)=1, y'(0)=b, y''(0)=0,  (((d^3)y)/(dt^3))(0)=0.  Plot the solution for  b=-2, -1, 0, 1, and 2, and for 0<t<5.

Solution

p2eq = D[y[t],{t,4}]+4*D[y[t],{t,3}]+14*y''[t]+20*y'[t]+25*y[t]==0
ic2a = y[0]==1
ic2b = y'[0]==b
ic2c = y''[0]==0
ic2d = (D[y[t],{t,3}]/.(t->0))==0

sol2=DSolve[{p2eq,ic2a,ic2b,ic2c,ic2d},y[t],t]

Table[sol2,{b,-2,2}];
Plot[y[t]/.%,{t,0,5}]

Inhomogeneous Second Order

If the right-hand side is simple enough, Mathematica will provide a solution of a forced equation as simply as in the unforced case:

sec1=y''[t]+3*y'[t]+10*y[t]==Sin[3*t]
DSolve[sec1,y[t],t]

However, as can be seen, sometimes Mathematica doesn’t put the answer in the simplest form up front.  So then we just use Simplify:

Simplify[%]

Initial conditions are handled exactly the same:

DSolve[{sec1,y[0]==0,y'[0]==0},y[t],t]
Simplify[%]

However, if the right-hand side is too complicated, Mathematica will not yield an explicit solution.

sec2 = y''[t]+y[t]==Cos[Exp[t]]
DSolve[sec2,y[t],t]

Note that the solution is expressed in variation-of-parameters form.

As long as one has initial conditions, however, one can use the usual numerical solution techniques:

sol2 = NDSolve[{sec2,y[0]==1,y'[0]==0},y,{t,0,10}]
y[3]/.sol2

Plotting works the same as before:

Plot[y[t]/.sol2,{t,0,10}]

Exercise

1.  Solve the differential equation y''+3y'-y=(e^(3t)), both in general and with the initial condition y(0)=3, y'(0)=1.  Simplify your answers.

Solution

eq1=y''[t]+3*y'[t]-y[t]==Exp[3*t]
ic1=y[0]==3
ic2 = y'[0]==1

DSolve[eq1,y[t],t];
Simplify[%]
DSolve[{eq1,ic1,ic2},y[t],t];
Simplify[%]

Inhomogeneous Higher Order

Mathematica can also solve higher-order equations with nonzero right-hand sides.

hleft = D[y[t],{t,4}]-2*D[y[t],{t,3}]-y''[t]-2*y'[t]-2*y[t]
DSolve[hleft==Sin[3*t],y[t],t]

By the method of undetermined coefficients, we expect the particular solution to be proportional to cos(3t) and sin(3t), which is clear once we use Simplify:

Simplify[%]

Note that the sin(t)terms are part of the homogeneous solution. 

Just as before, we can impose initial conditions if needed:

hic1a = y[0]==1
hic1b = y'[0]==0
hic1c = y''[0]==1
hic1d = (D[y[t],{t,3}]/.(t->0))==-1
DSolve[{hleft==Sin[3*t],hic1a,hic1b,hic1c,hic1d},y[t],t]
Simplify[%]

The same sets of commands also hold for solving more complicated forced equations numerically:

high3 = (1+Sin[t])*D[y[t],{t,4}]-2*(t+3)*D[y[t],{t,3}]-t*y''[t]+2*y'[t]+(t+3)*y[t]==-10
numhigh3 = NDSolve[{high3,hic1a,hic1b,hic1c,hic1d},y,{t,0,1}];
y[1]/.numhigh3

Plot[y[t]/.numhigh3,{t,0,1},PlotRange->All]

Exercise

1.  Write the solution of (((d^4)y)/(dt^4))+7 (((d^3)y)/(dt^3))+18y''+27y'+18y=sin(t), y(0)=a, y'(0)=0, y''(0)=0,  (((d^3)y)/(dt^3))(0)=0.  Plot the soluution for  a=1, 2, 3, 4, and 5, and for 0<t<5.

Solution

p2eq = D[y[t],{t,4}]+7*D[y[t],{t,3}]+18*y''[t]+27*y'[t]+18*y[t]==Sin[t]
ic2a = y[0]==a
ic2b = y'[0]==0
ic2c = y''[0]==0
ic2d = (D[y[t],{t,3}]/.(t->0))==0

Table[NDSolve[{p2eq,ic2a,ic2b,ic2c,ic2d},y,{t,0,5}],{a,1,5}];
Plot[y[t]/.%,{t,0,5}]

Cells

When organizing your work, it is important to keep in mind the concept of a cell.  This is the smallest group in Mathematica, and are set off by brackets on the sides. There are three important types of cells:

1.  Text cells are cells like this where you type in your comments.  They are denoted by two horizontal lines on the top of the bracket, as shown at right.

2.  The next are input cells, like the one below, where you type your commands  They are denoted by a triangle at the top of the bracket.

eqcell=y''[t]+3*y[t]==2*Sin[8*t]
DSolve[eqcell,y[t],t]

3.  Once you have executed an input cell, it creates one output cell for each command.  They are denoted by the same triangle with a horizontal line directly below.

Note also that there is now a second large bracket on the right of the three cells.  They now form a group, which can be collapsed by double-clicking on it.  Once the group is collapsed, it shows an arrow at the bottom of the bracket.

By default, Mathematica will try to do grouping automatically.  If for some reason you want to group cells together in some other way (as I do for each section), then you can select the cells you want to group and select Cell..Grouping..Group (or Ungroup, as you like).