Math 216 - Assignment 4 - Higher Order Equations and Systems of Equations

Due: Monday, April 16. Nothing accepted after Tuesday, April 17. This is worth 15 points. 10% points off for being late. You may work by yourself or in pairs. If you work in pairs it is only necessary to turn in one set of answers for each pair. Put both your names on it.

Do Problems 1 - 6 in the discussion below. Copy and paste the input and output for each problem from the Command Window (or plot window) to a Microsoft Word file. Do this after you are satisfied with your input and output. Label the work for each problem in the Word file: Problem 1, Problem 2, etc. Print a copy of this file to hand in. Or use a Live Script.

Symbolic Solution of higher order equations

MATLAB can find explicit solutions to some higher order equations using dsolve, but unless the equation has constant coefficients or a very particular form, solutions cannot be written explicitly using elementary functions. Consider the equation y'' + 3y' + 2y = 0. Here is the general solution.

>> syms y(t) >> dsolve(diff(y,2) + 3*diff(y, 1) + 2*y == 0) ans =

C1*exp(-t) + C2*exp(-2*t)

We can give partial initial conditions

>> dsolve(diff(y,2) + 3*diff(y, 1) + 2*y == 0, y(0) = 2) ans =

C5*exp(-2*t) - exp(-t)*(C5 - 2)

or complete initial conditions

1 >> Dy = diff(y, t); >> dsolve(diff(y,2) + 3*diff(y, 1) + 2*y == 0, y(0) = 2, Dy(0) == 1) ans =

5*exp(-t) - 3*exp(-2*t)

Problem 1: Find the general solution of y'' +2y' +17y = 0. Find the solution that satisfies the initial conditions y(0) = 1 and y'(0) = -1. Plot this solution for 0  t  10.

Linear equations with variable coefficients are typically unsolvable, or have solutions expressed using special functions defined for this purpose. For example, the solution to the equation y'' + ty = 0 involves the Airy functions.

>> dsolve(diff(y,2) + t*y == 0) ans =

C8*airy(0, -t) + C9*airy(2, -t)

Problem 2: Find the general solution of t2y'' - 12y = 0. Find the solution that satisfies the initial conditions y(1) = 3 and y'(1) = 5. Plot this solution for 0.1 < t  4.

Here is the nonlinear equation y'' + = 0.

>> dsolve(diff(y,2) + diff(y,1)/y == 0)

Warning: Explicit solution could not be found; implicit solution returned. ans = solve(int(1/(C10 - log(y)), y, 'IgnoreSpecialCases', true, 'IgnoreAnalyticConstraints', true) - t - C12 == 0, y)

Problem 3: Find the general solution of 4t2y'' + 4ty' + (4t2 - 1)y = 0.

2 Symbolic solution of systems

One can solve simple systems of linear differential equations with constant coefficients by hand either using substitution, elimination with differential operators or by writing the system in matrix form and solving using eigenvalues and eigenvectors.

In MATLAB one can use dsolve to solve a constant coefficient linear system. We write the system as a vector of equations. For example, to solve with the initial conditions we do the following.

>> syms x(t) y(t) >> [x(t), y(t)] = dsolve([diff(x,t) == y-2, diff(y,t) == 3 - 2*x], x(0) == 1, y(0) == 0) x(t) =

3/2 - (3*cos(atan(2*2^(1/2)) - 2^(1/2)*t))/2 y(t) =

2 - (3*8^(1/2)*cos(atan(2^(1/2)/4) + 2^(1/2)*t))/4

There are three different plots that reveal different properties of the solutions. The first two are just plots of x and y vs t as t varies over some range. Here are these two for the solution in the example above.

>> tspan = linspace(0, 10, 100); >> plot(tspan, x(tspan)) >> grid on >> title('x = x(t)') >> xlabel('t') >> ylabel('x') >> plot(tspan, y(tspan)) >> grid on >> title('y = y(t)') >> xlabel('t') >> ylabel('y')

3 As you can see both from the formulas and the graphs, both x and y are periodic functions of t. The third graph plots the ordered pairs (x(t), y(t)) as t varies over some range. This graph is a curve in the xy plane called the trajectory. Here is the trajectory for this solution.

>> plot(x(tspan), y(tspan)) >> grid on >> title('Trajectory: (x(t), y(t))') >> xlabel('x') >> ylabel('y') >> axis equal >> axis([-0.5, 3.5, -0.5, 4.5])

The trajectory is the ellipse at the right. The command axis equal made the scales on the two axes the same. The trajectories of the solutions of systems of differential equations can have a variety of interesting shapes.

Problem 4:Find the general solution of . Find the solution that satisfies the initial conditions . Make the following three plots. First, plot x versus t for 0  t  10. Then, plot y versus t for 0  t  10. Finally, plot y versus x for 0  t  10 to create the trajectory.

Numerical approximations

We can approximate solutions to systems of equations with ode45 just like we did with a single equation. Recall ode45 is a modified Runge-Kutta method which is good for most equations.

Consider the system with the initial conditions . Suppose we want an approximate solution on the interval 0  t  3.

Before using ode45 we need to write the system using vector notation, i.e. we write the two equations in terms of x1 and x2 instead of x and y. Letting x1 = x and x2 = y, the equations become and the initial conditions become . Then we generate a numerical solution as follows.

>> [tSol, xSol] = ode45(@(t,x) [x(1)*x(2)+2; x(2)+2*x(1)+1], [0 3], [-2 1.5]);

The equations are listed as entries in a column vector, and the initial conditions x1(0) = −2, x2(0) = 1.5 are given as a vector as well. Again, there are three plots: x vs t, y vs t and finally the trajectory where we plot (x(t), y(t)) for t in some interval

4 >> plot(tSol, xSol(:,1)) >> grid on >> title('x = x(t)') >> xlabel('t') >> ylabel('x') >> plot(tSol, xSol(:,2)) >> grid on >> title('y = y(t)') >> xlabel('t') >> ylabel('y') >> plot(xSol(:,1), xSol(:,2)) >> grid on >> title('Trajectory: (x(t), y(t))') >> xlabel('x') >> ylabel('y') >> axis equal

This produces the graphs below.

Problem 5: Find a numerical approximation to the solution of that satisfies the initial conditions . Plot x and y versus t for 0  t  10 and also the corresponding trajectory in the xy plane.

5 To approximate the solution of a higher order equation we need to rewrite it a first order system by introducing the new variables y1 = y and y2 = y'. For example, suppose we want to approximate the solution to y'' + 3y' + 2y = 0 that satisfies the initial conditions y(0) = 2 and y'(0) = 1. We let y1 = y and y2 = y'. Then the equation becomes y2' + 3y2 + 2y1 = 0. Combining with the definition y2 = y' we get the system together with the initial conditions . Suppose we want an approximation on the interval 0  t  20. Then we can input it into ode45 as follows.

>> [tSol, ySol] = ode45(@(t,y) [y(2); - 2*y(1) - 3*y(2)], [0 20], [2 1]);

Here is a plot of the approximate solution.

>> plot(tSol, ySol(:,1))

Problem 6: Find a numerical approximation to the solution of the van der Pol equation y'' - (1 – y2)y' + y = 0 that satisfies the initial conditions y(0) = 1 and y'(0) = 0. Plot y versus t for 0  t  30.

6