Demo 3.6

Second order inhomogeneous differential equations with  constant coefficients.

We can use Mathematica  to find solutions of equations that can be solved with the method of undetermined coefficients. 
In the following a palette is given, where simply the data a, b, c, and g(t)  of the inhomogeneous equation a y'' + b y' + cy = g(t) have to be filled in.  Then the solutions of the characteristic equation as well as of the inhomogeneous differential equation are computed.

({{Constant Coefficients}, {\(Clear[a, b, c, y]; 
            
{a, b, c, g[t]} = {\[SelectionPlaceholder], 
                \[SelectionPlaceholder], \[SelectionPlaceholder], 
                \[SelectionPlaceholder]}; 

            a\ \(y'\)'\  + \ b\ y'\  + \ c\ y\  == \ g[t]\)}, {Solve[a (r^2) + b r + c == 0, r]}, {soln=
	DSolve[a y''[t]+b y'[t]+c y[t]==g[t],y[t],t]
											//Simplify;	\(y[t_, c1_, c2_] = 
                \(y[t] /. First[soln]\)

                  	\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  /. 
                  \ {C[1]\  -> \ c1, C[2]\  -> c2}\)}})

Example 1.

y'' + 3 y' = (e^(-3 t))(t^2)+2(t^4)+ sin 3t

\(Clear[a, b, c, y]; 
    
{a, b, c, g[t]} = {1, 3, 0, 
        2  t\^4 + \(t\^\(2\ \)\) E\^\(\(-3\) t\) + Sin[3*t]}; 

    a\ \(y'\)'\  + \ b\ y'\  + \ c\ y\  == \ g[t]\)

Solve[a (r^2) + b r + c == 0, r]

Hence the general solution of the corresponding homogeneous equation  y'' + 3 y' = 0 is given by   
y = c1 (E^(-3 t))+c2. 
The general solution of the inhomogeneous equation is given as

soln=
	DSolve[a y''[t]+b y'[t]+c y[t]==g[t],y[t],t]
											//Simplify;	\(y[t_, c1_, c2_] = 
        \(y[t] /. First[soln]\)

          	\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  /. 
          \ {C[1]\  -> \ c1, C[2]\  -> c2}\)

Expand[y[t, c1, c2]]

We can use the plot commands from Demo.3.1.nb to show some of the solutions.

\(Plot[Evaluate[Table[y[t, c1, 3], {c1, \(-4\)\ , 4\ , 2\ }]], 

      		{t, \(-2\)\ , 2\ }, AspectRatio -> 1]\)

A particular solution of the inhomogeneous equation is simply given by specifying the constants, say to c1 = 3= c2

y[t, 3, 3]

Example 2.

y'' + y = t (1+ sin t)

\(Clear[a, b, c, y]; 
{a, b, c, g[t]} = {1, 0, 1, t*\((1 + Sin[t])\)}; 

    a\ \(y'\)'\  + \ b\ y'\  + \ c\ y\  == \ g[t]\)

Solve[a (r^2) + b r + c == 0, r]

which means, that the general solution of the homogeneous equation  y'' + y = 0  is given as 
y=c1 sin(t) + c2 cos(t).
As before, we get the general solution of the inhomogeneous equation via

soln=
	DSolve[a y''[t]+b y'[t]+c y[t]==g[t],y[t],t]
											//Simplify;	\(y[t_, c1_, c2_] = 
        \(y[t] /. First[soln]\)

          	\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  /. 
          \ {C[1]\  -> \ c1, C[2]\  -> c2}\)

Expand[y[t, c1, c2]]

A particular solution is e. g.

y[t, 3, 5]

\(\(Plot[Evaluate[y[t, 3, 5]], {t, \(-10\)\ , 10\ }
	, AspectRatio -> 1]
      \ \)\)

Of course, also y[t,0,-1/8] is a particular solution

y[t, 0, -1/8]

\(\(Plot[Evaluate[y[t, 0, \(-1\)/8]], {t, \(-15\)\ , 15\ }
	, 
      AspectRatio -> 1]\ \)\)

The following equations do not fit into the "undetermined coefficients" pattern.

Example 3.

y'' - 5 y' + 6y = sin  (t^2)

\(Clear[a, b, c, y]; 
{a, b, c, g[t]} = {1, \(-5\), 6, Sin[t\^2]}; 

    a\ \(y'\)'\  + \ b\ y'\  + \ c\ y\  == \ g[t]\)

Solve[a (r^2) + b r + c == 0, r]

soln=
	DSolve[a y''[t]+b y'[t]+c y[t]==g[t],y[t],t]
											//Simplify;	\(y[t_, c1_, c2_] = 
        \(y[t] /. First[soln]\)

          	\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  /. 
          \ {C[1]\  -> \ c1, C[2]\  -> c2}\)

Example  4.

y''- 5 y' + 6y = log t

\(Clear[a, b, c, y]; 
{a, b, c, g[t]} = \ {1, \(-5\), 6, Log[t]}; 

    a\ \(y'\)'\  + \ b\ y'\  + \ c\ y\  == \ g[t]\)

Solve[a (r^2) + b r + c == 0, r]

soln=
	DSolve[a y''[t]+b y'[t]+c y[t]==g[t],y[t],t]
											//Simplify;	\(y[t_, c1_, c2_] = 
        \(y[t] /. First[soln]\)

          	\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  /. 
          \ {C[1]\  -> \ c1, C[2]\  -> c2}\)