Demonstration of solutions of higher order linear constant coefficient ODE'S

Examples of using Mathematica  NSolve and Solve functions to solve polynomial equations:

\(\(NSolve[x\^5 - 3\ x\^4 + 3\ x\^2 - 3\ x + 2 == 0, x]
\)\)

How   are repeated roots treated ?

Expand[
      (((x - 2))^3) (x - 1) (x - 3 + 2 I) (x - 3 - 2 I)]NSolve[% == 0, x]

The Mathematica NSolve function provides only approximate numerical solutions. The Mathematica  Solve  function can often be used to get exact solutions for algebraic equations:

\(
Solve[x^5 - x^4\  + \ x^3\  - x^2\  - x\  + 1\  == 0, \ x]\)N[%]

Sometimes the Solve function provides a bit more information than a person can handle;  open the following closed cell to see an example of such information overload.

\(\(Solve[x\^5 - 3\ x\^4 + 3\ x\^2 - 3\ x + 2 == 0, x]
\)\)

Examples of using Mathematica to solve a higher order, linear, constant coefficient,  homogeneous initial value problem:

Example:  2  (y^((4))) -1 (y^((3)))-9 y''+4 y'+4 y=0

First we find the roots of the characteristic equation.

p = 2  (x^4) - 1 (x^3) - 9 (x^2) + 4 x + 4NSolve[p == 0,  x]

\(\(
α\  = \ x //. \ NSolve[p == 0, \ x]\)\)

The general solution to the differential equation has the following form:

c  =  {c1,  c2,  c3,  c4}Clear[φ]φ[t_]  = 
      (∑_(i = 1)^4) c[[i]] 
          Exp[α[[i]] t]

We compute the first, second and third derivatives of φ .

phifirst  = Derivative[1][φ][t]phisecond  = Derivative[2][φ][t]phithird  =   Derivative[3][φ][t]

We evaluate the function and its first, second, and third derivatives at t = 0.

phi0  =  φ[0]phi1  =  phifirst  /.  t -> 0phi2  =  phisecond  /.  t -> 0phi3  =  phithird  /.  t -> 0

We solve the inital conditions
φ(0) = -2
φ'(0) = 0
φ''(0) = -2
φ'''(0) = 0
for the constants  c1, c2, c3, c4.

\(Solve[{phi0 == \(-2\), \ phi1\  == \ 0, \ phi2\  == \ \(-2\), \ 
	
        phi3\  == \ 0}, \ c]\)φ [t] //.  %

Basically, having done the thing once, we have done it once and for all!  Let's change the example  to
Derivative[4][y]+3 Derivative[3][y]-9 y''+4 y'+4 y=0

p = (x^4)  +  3 (x^3) - 9 (x^2) + 4 x + 4\(NSolve[p == 0, \ x]

\)α  =  x //.  NSolve[p == 0,  x]\(	\(c\  = \ {c1, \ c2, \ c3, \ c4}; \)\)

Since some of the roots of the algebraic equation are complex, we can use real valued trigonometric solutions rather than complex valued exponential solutions.

φ[t_] = 
      c1 Exp[α[[1]] t] + 
        c2 Exp[α[[2]] t] + 
        c3 Exp[Re[α[[3]]] t] 
          Cos[Im[α[[3]]] t] + 
        c4 Exp[Re[α[[3]]] t] 
          Sin[Im[α[[3]]] t]

phifirst  = Derivative[1][φ][t]phisecond  = Derivative[2][φ][t]\(phithird\  = \ \ \(\(Derivative[3]\)[φ]\)[t]
\)phi0  =  φ[0]phi1  =  phifirst  /.  t -> 0phi2  =  phisecond  /.  t -> 0\(phi3\  = \ phithird\  /. \ t -> 0
	\)

Now we can solve for  initial conditions
φ(0) = -1,  φ'(0) = 0, φ''(0) = 4, φ'''(0) = 0.

\(Solve[{phi0 == \(-1\), \ phi1\  == \ 0, \ phi2\  == \ 4, \ 
	
        phi3\  == \ 0}, \ c]\)φ  //.  %

Example of using Mathematica to  solve a higher order  inhomogeneous problem:

Consider the example:
Derivative[4][y]-Derivative[3][y]-y''+y'=(t^2) + 4 + t Sin[t]
Let's find a particular solution to this inhomogeneous equation.

First we find the roots of the characteristic equation:

\(
p\  = \ x^4\  - \ x^3\  - \ x^2\  + \ x\)Solve[p == 0,  x]

Since zero is a root of the characteristic equation, with multiplicity 1,  we can seek a solution to the inhomogenous equation
Derivative[4][y]-Derivative[3][y]-y''+y'=(t^2) + 4  
of the form     t (A (t^2) + B t + C)

We apply the differential operator L[y]=Derivative[4][y][t]-Derivative[3][y][t]-y''[t]+y'[t]
to a tentative solution of the form
t (A (t^2) + B t + C).

\(L[y_]\  = \ 
      \(\(Derivative[4]\)[y]\)[t]\  - \ \(\(Derivative[3]\)[y]\)[t]\  - \ 

        \ \ \(\(Derivative[2]\)[y]\)[t]\  + \ \(\(Derivative[1]\)[y]\)[t]\)g[t_]  =  t (A (t^2) + B t + C)\(Expand[	L[g]]\)

We can pick out coefficients of various powers of   t  in
L[g].

\(Coefficient[Expand[	L[g]], \ t^2]\)\(Coefficient[Expand[	L[g]], \ t]\)\(Coefficient[Expand[	L[g]], \ t, 0]\)

Now we have to match coefficients with those in    (t^2) + 4, and then substitute the resulting values for A, B, C in the solution g[t].

\(
ssolve\  = \ 
      Solve[{Coefficient[Expand[	L[g]], \ t^2]\  == \ 1, 

          Coefficient[Expand[	L[g]], \ t]\  == \ 0, 
	
          Coefficient[Expand[	L[g]], \ t, 0]	 == 4		}, 
	{A, B, C}]


    
\)φ1 =  Expand[g[t]  //.  ssolve ][[1]]

Next we work on the  problem 
Derivative[4][y]-Derivative[3][y]-y''+y'=t Sin[t].
Since  i   (the square root of -1)   is not a root of the characteristic equation , we have to seek a solution of the form
h(t) = (A t + B) Sin[t] + (C t + D) Cos[t].

h[t_] = (A t + B) Sin[t] + (C t + D) Cos[t]\(	Expand\ [\ L[h]]\)

We need to match coefficients of 
 (t^k) Cos[t]  and
  (t^k) Sin[t] 
  in this expression with those in the expression 
   t Sin[t].  
  We have an excess of information, so we just pick out  a sufficient number of equations to solve:

\(
Coefficient[	Expand\ [\ L[h]], \ t\ \ Cos[t]]\ 
\)\(Coefficient[	Expand\ [\ L[h]], \ \ Cos[t]]\  //. \ t -> \ 0\)\(Coefficient[	Expand\ [\ L[h]], \ t\ \ Sin[t]\ ]\ \)\(Coefficient[	Expand\ [\ L[h]], \ \ Sin[t]]\  //. \ t -> \ 0\)

\(ssolve\  = \ 
      Solve[
	{Coefficient[	Expand\ [\ L[h]], \ t\ \ Cos[t]]\  == 0, 
	
          \((Coefficient[	Expand\ [\ L[h]], \ \ Cos[t]]\  //. t -> 0)\)\  == 
            0, 
	Coefficient[	Expand\ [\ L[h]], \ t\ Sin[t]]\  == 1, 
	
          \((Coefficient[	Expand\ [\ L[h]], \ \ Sin[t]]\  //. \ t -> \ 0)
              \) == 0		}, 	
		{A, B, C, D}]		

\)φ2  =  Expand[h[t]  //.  ssolve][[1]]

The particular solution to the original inhomogeneous equation
Derivative[4][y]-Derivative[3][y]-y''+y'=(t^2) + 4 + t Sin[t]
is the sum of φ1 and φ2.
We check our work by applying the differential operator L to this sum:

\(
φp[t_]\  = \ φ1\  + \ φ2\)L[φp]

Consider the example:
Derivative[4][y]-Derivative[3][y]-y''+y'=(t^2) + 4 + t Sin[t]
Let's find  the general  solution to this inhomogeneous equation.

The general solution to the associated homogeneous equation:

\(
p\  = \ x^4\  - \ x^3\  - \ x^2\  + \ x\)Solve[p == 0,  x]α  =  x //.  Solve[p == 0,  x]\(	c\  = \ {c1, \ c2, \ c3, \ c4}; 


    φ0[t_]\  = \ 
      c1\ Exp[\(-t\)]\ \  + \ c2\  + \ c3\ Exp[t]\  + \ c4\ t\ Exp[t]
\)

The general solution to the inhomogeneous equation is the general solution to the associate homogeneous equation plus the particular solution to the inhomogeneous equation which was found before:

φ[t_]  =  φp[t]  +  φ0[t]

Consider the example:
Derivative[4][y]-Derivative[3][y]-y''+y'=(t^2) + 4 + t Sin[t]
Let's find the particular solution to this equation which satisfies initial conditions
y(0) = 2
y'(0) = 0
y''(0) = 0
y'''(0) = -1.

\(\(
φ[t]\)\)

phifirst  = Derivative[1][φ][t]phisecond  = Derivative[2][φ][t]\(phithird\  = \ \ \(\(Derivative[3]\)[φ]\)[t]
\)phi0  =  φ[0]phi1  =  phifirst  /.  t -> 0phi2  =  phisecond  /.  t -> 0phi3  =  phithird  /.  t -> 0

Here, finally is our solution:

\(Solve[{phi0 == 2, \ phi1\  == \ 0, \ phi2\  == \ 0, \ 
	
        phi3\  == \ \(-1\)}, \ c]\)φ[t]  //.  %