- 14 -
the first derivative of the function y with Dy. The second derivative of y is represented
with D2y. For example, the command for solving y''-3y'+2y = sin x.
>> dsolve('D2y-3*Dy+2*y=sin(x)', 'x')
ans =
3/10*cos(x)+1/10*sin(x)+C1*exp(x)+C2*exp(2*x)
If we have the initial conditions y(0) = 10, y'(0)=-10, we would have:
>> dsolve('D2y-3*Dy+2*y=sin(x)', 'y(0)=1', 'Dy(0)=-1', 'x')
ans =
3/10*cos(x)+1/10*sin(x)+5/2*exp(x)-9/5*exp(2*x)
For the equations that can not be solved in terms of elementary functions, we use the
numerical methods. We can illustrate the ode45 command for the second order
equations on the equation y'' + x y' + y = 0. For ode45, the second order differential
equation must be solved for y''. In this case we have that y'' = -x y' - y. The first derivative
of y is represented with y(2) and function y with y(1). Suppose that we have initial
conditions y(0)=1 and y'(0)=0. As for the first order equations, we then indicate the
interval on which we want to graph the solution, say [0, 5] and the initial conditions.
>> f=inline('[y(2); -y(2)*x-y(1)]','x','y');
>> ode45(f, [0 5], [1 0])
The output represents two functions. The blue function is the solution of the equation
and the green function is the derivative.
We can obtain the numerical values of the solution as well.
>> [x, y] = ode45(f, [0 5], [1 0])
The vector y will consist of two columns. The first consists of the values of the solution y
at points between 0 and 3 and the second consists of the values of the derivative y' at
these points.
Practice problems 8
1. Graph the direction field of the differential equation y' = (y²-1)(x²-1). Let x takes the
values between 0 and 5 with step size .2 and y takes the values between -3 and 3 with
same step size.
2. Graph the solution of the initial value problem y' = -y + 5 cos 10x - sin 2x, y(0)=0 on
the interval [0, 5]. Find the value of the solution at 3.
3. Find the exact solution of the equation y''-4 y'+4 y=