Math 308 Week 8 Solutions
There is a solution manual to Chapter 4 online: www.pearsoncustom.com/tamu math/.
This online solutions manual contains solutions to some of the suggested problems. Here
are solutions to suggested problems that cannot be found in the online solutions manual.
Matlab 5
In exercises 1-6 perform the following tasks for the given initial value problem:
a) Find the exact solution.
b) Use MATLAB to plot on a single figure window the graph of the exact solution,
together with the plots of the solutions using each of the three methods (eul, rk2,
rk4) with the given step size h. Use a distinctive marker (type help plot) for help
on available markers) for each method. Label the graph appropriately and add a
legend to the plot.
1. x0 = x sin(3t), with x(0) = 1, on [0, 4]; h = 0.2
Answer: First, we use dsolve to find the solution. We get:
x(t) =
e− cos(3t)/3
cosh(1/3) − sinh(1/3)
Next, we have Matlab plot the above solution:
>> t = 0:.01:4;
>> g = inline('exp(-cos(3*t)/3)/(cosh(1/3)-sinh(1/3)','t');
>> plot(t, g(t), '-');
The third entry in the plot command says to use a solid line for this graph.
Now, we use eul, rk2, and rk4. Here are the Matlab commands:
>>
>>
>>
>>
f= inline('x*sin(3*t)', 't',
[t1, x1] = eul(f, [0, 4], 1,
[t2, x2] = rk2(f, [0, 4], 1,
[t3, x3] = rk4(f, [0, 4], 1,
'x');
0.2);
0.2);
0.2);
Now, we plot the results on the same figure as the plot of the actual solution. We
will use dotted lines for these graphs, and we will include a legend:
>>
>>
>>
>>
>>
>>
hold on
plot(t1, x1, ':');
plot(t2, x2, '-.');
plot(t3, x3, '--');
legend('actual', 'eul', 'rk2', 'rk4', 3);
shg
1
The final entry in the legend command says which corner to put the legend in. Here
is the resulting graph:
2
actual
eul
rk2
rk4
1.8
1.6
1.4
1.2
1
0.8
0
0.5
1
1.5
2
2.5
3
3.5
4
If instead of using dotted lines, we wish to have colored lines, we can enter the commands:
>>
>>
>>
>>
>>
>>
hold on
plot(t1, x1, 'r');
plot(t2, x2, 'g');
plot(t3, x3, 'k');
legend('actual', 'eul', 'rk2', 'rk4', 2);
shg
2
1.8
1.6
1.4
1.2
actual
eul
rk2
rk4
1
0.8
0
0.5
1
1.5
2
2
2.5
3
3.5
4
2. y 0 = (1 + y 2 ) cos(t), with y(0) = 0, on [0, 6]; h = 0.5
Answer: We use the same method as in problem 1. The solution to the initial value
problem is:
y = tan(sin t)
The resulting graphs are:
2
actual
eul
rk2
rk4
1.5
1
0.5
0
−0.5
−1
−1.5
−2
0
1
2
3
4
5
6
2
actual
eul
rk2
rk4
1.5
1
0.5
0
−0.5
−1
−1.5
−2
0
1
2
3
3
4
5
6
3. z 0 = z 2 cos(2t), with z(0) = 1, on [0, 6]; h = 0.25
Answer: We use the same method as in problem 1. The solution to the initial value
problem is:
y=
−1
cos t sin t − 1
The resulting graphs are:
2.4
actual
eul
rk2
rk4
2.2
2
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0
1
2
3
4
5
6
2.4
actual
eul
rk2
rk4
2.2
2
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0
1
2
3
4
4
5
6
4. x0 = x(4 − x)/5, with x(0) = 1, on [0, 6]; h = 0.5
Answer: We use the same method as in problem 1. The solution to the initial value
problem is:
x=
4
1 + 3e−4t/5
The resulting graphs are:
4
3.5
3
2.5
2
actual
eul
rk2
rk4
1.5
1
0
1
2
3
4
5
6
4
3.5
3
2.5
2
actual
eul
rk2
rk4
1.5
1
0
1
2
3
5
4
5
6
5. y 0 = 2ty, with y(0) = 1, on [0, 2]; h = 0.2
Answer: We use the same method as in problem 1. The solution to the initial value
problem is:
y = et
2
The resulting graphs are:
60
actual
eul
rk2
rk4
50
40
30
20
10
0
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
0.6
0.8
1
1.2
1.4
1.6
1.8
2
60
actual
eul
rk2
rk4
50
40
30
20
10
0
0
0.2
0.4
6
6. z 0 = (1 − z)t2 , with z(0) = 3, on [0, 2]; h = 0.25
Answer: We use the same method as in problem 1. The solution to the initial value
problem is:
z = 1 + 2e−t
3 /3
The resulting graphs are:
3
actual
eul
rk2
rk4
2.8
2.6
2.4
2.2
2
1.8
1.6
1.4
1.2
1
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
3
actual
eul
rk2
rk4
2.8
2.6
2.4
2.2
2
1.8
1.6
1.4
1.2
1
0
0.2
0.4
0.6
0.8
1
7
1.2
1.4
1.6
1.8
2
22. Simple substitution will reveal that x(t) = π/2 is a solution of x0 = et cos x. Moreover,
both f (t, x) = et cos x and ∂f /∂x = −et are continuous everywhere. Therefore,
solutions are unique and no two solutions can share a common point (solutions cannot
intersect). Use Euler’s method with a step size h = 0.1 to plot the solution of
x0 = et cos x with initial conditions x(0) = 1 on the interval [0, 2π] and hold the
graph (hold on). Overlay the graph of x = π/2 with the command
line([0, 2*pi], [pi/2, pi/2], 'color', 'r')
and note that the solutions interesect. Does reducing the step size help? If so, does
this reduced step size hold up if you increase the interval to [0, 10]. How do rk2 and
rk4 perform on this same problem?
Answer: First, we perform Euler’s method with step size h = .1. The commands
are:
>> f = inline('exp(t)*cos(x)', 't', 'x')
>> [t, x] = eul(f, [0,2*pi], 1, 0.1);
>> plot(t, x)
We see that it gets fairly messed up towards the end. We can plot the line x = π/2
on the same figure:
>> hold on
>> line([0, 2*pi], [pi/2, pi/2], 'color', 'r')
We get the following graph:
30
20
10
0
−10
−20
−30
−40
−50
−60
0
1
2
3
4
8
5
6
7
We see that the Euler’s method solution is intersecting the line x = π/2. If you
try reducing the step size, you will eventually find a step size for which the result
of Euler’s method does not intersect the line x = π/2. For example, the step size
h = .005 works, and gives the following graph:
1.7
1.6
1.5
1.4
1.3
1.2
1.1
1
0
1
2
3
4
5
6
7
However, this step size does not work on the interval [0, 10]:
600
400
200
0
−200
−400
−600
−800
0
1
2
3
4
5
9
6
7
8
9
10
If you try rk2 and rk4, you will see that they both have the same problem. Here is
a graph of rk2 on the interval [0, 2π] with step size h = .1:
10
0
−10
−20
−30
−40
−50
−60
−70
−80
0
1
2
3
4
5
6
7
Here is a graph of rk4 on the interval [0, 10] with step size h = .1:
10
5
0
−5
−10
−15
−20
−25
−30
0
1
2
3
4
10
5
6
7
For all of the methods (eul, rk2, and rk4), you can choose your step size small
enough to work on any given interval. However, if you expand the interval, you will
need a smaller step size, and some intervals may require such a small step size that
the computation time becomes unreasonable.
If you look at the direction field of this differential equation in dfield7, you will
see why this is occurring. The slopes of solutions to the differential equation are
incredibly steep near for most points with t > 3 (of course, the slopes approach 0
at x = π/2, but you have to be really, really close to x = π/2 to get to the slopes
that are approaching 0). In dfield7, you can ask Matlab to compute the solution with
initial condition x(0) = 1 on the interval from t = 0 to t = 10. It successfully has the
solution approach the line x = π/2, but the computation gets slower and slower as t
becomes larger. Matlab is choosing smaller and smaller step sizes for larger values of
t, which is why it takes it so long to plot the solution.
23. The accuracy of any numerical method in solving a differential equation y 0 = f (t)
depends on how strongly the equation depends on the variable y. More precisely, the
constants that appear in the error bounds depend on the derivatives of f with respect
to y. To see this experimentally, consider the two initial value problems
y 0 = y,
y(0) = 1,
y 0 = et ,
y(0) = 1,
You will notice that the two problems have the same solution. For each of the three
methods described in this chapter compute approximate solutions to these two initial
value problems over the interval [0, 1] using a step size of h = 0.01. For each method
compare the accuracy of the solution to the two problems.
Answer: Here are the results of the computations (we’ll give 6 decimal places for
eul and rk2 and 14 decimal places for rk4):
0
y = y,
y 0 = et ,
eul
rk2
rk4
y(0) = 1 2.704814 2.718237 2.71828182823440
y(0) = 1 2.709705 2.718296 2.71828182846501
The actual value of e to 14 decimal places is 2.71828182845905. We can see that
for all of eul, rk2, and rk4, the approximation from the equation y 0 = et is more
accurate than the approximation from the equation y 0 = y.
Of course, the method of approximating e using the differential equation y 0 = et
requires being able to compute et for several values of t, so it would not be a useful
method for approximating e.
11
24. Remember that y(t) = et is the solution to the initial value problem y 0 = y, y(0) = 1.
Then e = e1 , and in MATLAB this is e = exp(1). Suppose we try to calculate e
approximately by solving the initial value problem, using the methods of this chapter.
Use step sizes of the form 1/n, where n is an integer. For each of Euler’s method, the
second Runge-Kutta method, and the fourth order Runge-Kutta method, how large
does n have to to get an approximation eapp which satisfies | eapp − e| ≤ 10−3 ?
Answer: Since we expect that the fourth order Runge-Kutta will work the best, we
will start with it. We use rk4 to approximate e using step size 1 and 1/2:
>> f = inline('y', 't', 'y')
>> [t, y] = rk4(f, [0, 1], 1, 1); y(size(y,1))
>> [t, y] = rk4(f, [0, 1], 1, 1/2); y(size(y,1))
Using step size h = 1, we get y(1) ≈ 2.7083, so that |eapp − e| = 0.0099, which is not
less than .001. Using step size h = 1/2, we get y(1) ≈ 2.7173, so that |eapp − e| =
.0009356, which is less than .001. Thus, for rk4 it works to use n = 2.
Now, we try rk2. We expect this to take larger n. We will create a chart for
n = 1, 2, 3, . . . . The relevant information for each n is eapp and |eapp − e|. We will
keep increasing n until we find an n such that |eapp − e| < .001.
n
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
eapp
2.5
2.64063
2.67918
2.69486
2.70271
2.70719
2.70998
2.71184
2.71314
2.71408
2.71479
2.71533
2.71575
2.71609
2.71637
2.71659
2.71678
2.71694
2.71708
2.71719
2.71729
|eapp − e|
0.21828
0.07766
0.03910
0.02343
0.01557
0.01109
0.00830
0.00644
0.00514
0.00420
0.00350
0.00295
0.00253
0.00219
0.00191
0.00169
0.00150
0.00134
0.00121
0.00109
0.00099
Thus, for rk2 we see that it works to use n = 21.
12
For eul, we expect n to be larger and it doesn’t seem feasible to compute eapp
starting with n = 1 till we get an n that works. Instead, you can jump around. Try
n = 1000 (which is not large enough), then try n = 5000, which is large enough.
Then, try some values in between, trying to narrow in on the smallest n that works.
You should get that n = 1359 is the smallest n that works.
Thus, our answer is:
For eul, n must be at least 1359.
For rk2, n must be at least 21.
For rk4, n must be at least 2.
NSS 4.9
10. Find a general solution to the differential equation using the method of variation of
parameters.
y 00 + 4y 0 + 4y = e−2x ln x
Answer: The corresponding homogeneous differential equation is y 00 + 4y 0 + 4y = 0,
with auxiliary equation r2 + 4r + 4 = 0, with solution r = −2 as a double root. Thus,
the solutions to the homogeneous differential equation are yh = c1 e−2x + c2 xe−2x .
We let y1 = e−2x and y2 = xe−2x . Then y10 = −2e−2x and y20 = e−2x − 2xe−2x . We
want to find a particular solution of the form
yp = v1 e−2x + v2 xe−2x
We get the equations:
v10 e−2x + v20 xe−2x = 0
v10 (−2e−2x ) + v20 (e−2x − 2xe−2x ) = e−2x ln x
We solve the equations for v10 and v20 using Cramer’s Rule:
¯
¯
¯
¯
xe−2x
¯
¯ −2x0
−2x
−2x ¯
¯ e
ln
x
e
−
2xe
−xe−4x ln x
¯
=
v10 = ¯¯
= −x ln x
−2x
−2x
¯
e−4x − 2xe−4x + 2xe−4x
¯
¯ e −2x −2xxe
¯ −2e
e
− 2xe−2x ¯
¯
¯
¯
¯ e−2x
0
¯
¯
¯ −2e−2x e−2x ln x ¯
e−4x ln x
¯
=
= ln x
v20 = ¯¯
−2x
−2x
¯
e−4x
¯
¯ e −2x −2xxe
¯ −2e
e
− 2xe−2x ¯
Thus:
Z
v1 =
1
1
−x ln x dx = − x2 ln x + x2 + C1
2
4
13
Z
v2 =
ln x dx = x ln x − x + C2
Since we just want to find one
Thus:
µ
1
yp = v1 y1 +v2 y2 = − x2 ln x +
2
particular solutions, we can ignore the C1 and C2 .
¶
µ
¶
1 2 −2x
1
3
−2x
2 −2x
x e +(x ln x − x) xe
=x e
ln x −
4
2
4
Thus, the general solution is
µ
y = c1 e−2x + c2 xe−2x + x2 e−2x
1
3
ln x −
2
4
¶
14. Find a general solution to the differential equation.
y 00 + y = tan x + e3x − 1
Answer: We can use the method of undetermined coefficients to solve the differential
equation y 00 + y = e3x − 1, then we will only need to use variation of parameters on
y 00 + y = tan x.
The auxiliary equation is r2 + 1 = 0, which has solutions r = ±i. Thus, the corresponding homogeneous differential equation has solutions yh = c1 cos x + c2 sin x. For
the differential equation y 00 + y = e3x − 1, we expect a particular solution of the form
yp = Ae3x + B. Then, yp0 = 3Ae3x and yp00 = 9Ae3x . Plugging into the differential
equation, we get
9Ae3x + Ae3x + B = e3x − 1
Thus:
10Ae3x + B = e3x − 1
Thus, A = 1/10 and B = −1, so a particular solution is yp = (1/10)e3x − 1.
Now, we need to use variation of parameters to solve the differential equation y 00 +y =
tan x. We have y1 = cos x and y2 = sin x. Thus, y10 = − sin x and y20 = cos x. We
want to find a particular solution of the form
yp = v1 cos x + v2 sin x
We get the equations:
v10 cos x + v20 sin x = 0
v10 (− sin x) + v20 cos x = tan x
We solve the equations for v10 and v20 using Cramer’s Rule:
¯
¯
¯
¯
0
sin
x
¯
¯
¯ tan x cos x ¯
− sin x tan x
¯=
v10 = ¯¯
= − sin x tan x
¯
cos2 x + sin2 x
¯ cos x sin x ¯
¯ − sin x cos x ¯
14
¯
¯
¯ cos x
¯
0
¯
¯
¯ − sin x tan x ¯
0
¯ = cos x tan x = sin x
v2 = ¯¯
¯
cos
x
sin
x
¯
¯
¯ − sin x cos x ¯
Thus:
Z
v1 =
− sin x tan x dx = sin x − ln | sec x + tan x| + C1
Z
v2 = sin x dx = − cos x + C2
Since we just want to find one particular solutions, we can ignore the C1 and C2 .
Thus, a particular solution to the differential equation y 00 + y = tan x is
yp = v1 y1 + v2 y2
= (sin x − ln | sec x + tan x|) cos x − cos x sin x
= − cos x ln | sec x + tan x|
To get a particular solution to the original differential equation, we combine the two
particular solutions:
yp = (1/10)e3x − 1 − cos x ln | sec x + tan x|
Thus, the general solution is
y = c1 cos x + c2 sin x + (1/10)e3x − 1 − cos x ln | sec x + tan x|
18. Find a general solution to the differential equation.
y 00 + 5y 0 + 6y = 18x2
Answer:
We can use the method of undetermined coefficients to solve this differential equation.
The auxiliary equation is r2 + 5r + 6 = 0, which has solutions r = −2, −3. Thus, the
homogeneous equation has solutions yh = c1 e−2x + c2 e−3x .
We expect a particular solution of the form yp = Ax2 + Bx + C. Then, yp0 = 2Ax + B
and yp00 = 2A. Plugging these into the differential equation, we get:
(2A) + 5(2Ax + B) + 6(Ax2 + Bx + C) = 18x2
Combining x2 , x, and constant terms, we get:
6Ax2 + (10A + 6B)x + (2A + 5B + 6C) = 18x2
Thus, 6A = 18, 10A + 6B = 0, and 2A + 5B + C = 0. Solving, we get that A = 3,
B = −5, and C = 19/6. Thus, the particular solution is
yp = 3x2 − 5x + 19/6
15
Thus, the general solution is
y = c1 e−2x + c2 e−3x + 3x2 − 5x + 19/6
22. The Bessel equation of order one half,
µ
¶
1
2 00
0
2
x y + xy + x −
y = 0,
4
x>0
has two linearly independent solutions,
y1 (x) = x−1/2 cos x,
y2 (x) = x−1/2 sin x
Find a general solution to the nonhomogeneous equation
¶
µ
1
2 00
0
2
x y + xy + x −
y = x5/2 ,
x>0
4
Answer: First, we should divide the differential equation by x2 to put it in the
appropriate form:
µ
¶
√
y0
1
00
y + + 1 − 2 y = x,
x>0
x
4x
Since y1 = x−1/2 cos x and y2 = x−1/2 sin x, we have
− cos x sin x
√ − √
2x x
x
− sin x cos x
√ + √
=
2x x
x
y10 =
y20
We want to find a particular solution of the form
yp = v1 x−1/2 cos x + v2 x−1/2 sin x
We get the equations:
v10 y1 + v20 y2 = 0
√
v10 y10 + v20 y20 =
x
To simplify later calculations, we can compute the Wronskian of y1 and y2 :
¯
¯
cos x
sin x
¯
¯
√
√
¯
¯
¯
¯
x
x
¯
¯
W [y1 , y2 ] = ¯
¯
¯ − cos x sin x − sin x cos x ¯
¯
√ − √
√ + √ ¯¯
¯
2x x
x
2x x
x
=
cos2 x cos x sin x cos x sin x sin2 x
−
+
+
x
2x2
2x2
x
1
cos2 x + sin2 x
=
=
x
x
16
We solve the equations for v10 and v20 using Cramer’s Rule:
¯
¯
¯ 0 x−1/2 sin x ¯
¯ √
¯
0
¯ x
¯
y
− sin x
2
v10 =
=
= −x sin x
W [y1 , y2 ]
1/x
¯ −1/2
¯
¯ x
cos x √0 ¯¯
¯
¯
y10
x ¯
cos x
v20 =
=
= x cos x
W [y1 , y2 ]
1/x
Thus:
Z
v1 =
−x sin x dx = − sin x + x cos x + C1
Z
v2 = x cos x dx = cos x + x sin x + C2
Since we just want to find one particular solutions, we can ignore the C1 and C2 .
Thus:
y p = v1 y 1 + v2 y 2
= (− sin x + x cos x) x−1/2 cos x + (cos x + x sin x) x−1/2 sin x
√
√
√
=
x cos2 x + x sin2 x = x
Thus, the general solution is
y = c1 x−1/2 cos x + c2 x−1/2 sin x +
√
x
24. Find a general solution to the differential equation given that y1 and y2 are linearly
independent solutions to the corresponding homogeneous equation for x > 0.
x2 y 00 − 4xy 0 + 6y = x3 + 1
y 1 = x2 ,
y 2 = x3
Answer: This is a Cauchy-Euler differential equation, so we can use the CauchyEuler method along with the method of undetermined coefficients. We use the substitution x = et , then
x = et
dy
dy
=
x
dx
dt
2
d2 y dy
dy
x2 2 =
−
dx
dt2
dt
This gives us the following differential equation:
dy
d2 y dy
−
− 4 + 6y = e3t + 1
2
dt
dt
dt
17
This becomes:
dy
d2 y
− 5 + 6y = e3t + 1
2
dt
dt
This differential equation has auxiliary equation r2 −5r+6 = 0 with solutions r = 2, 3.
Thus, the corresponding homogeneous equation has solutions yh = c1 e2t + c2 e3t (in
terms of x, this is yh = c1 x2 + c2 x3 , which agrees with the two homogeneous solutions
given in the problem). Since e3t is a solution to the homogeneous differential equation,
we expect a particular solution of the form yp = Ate3t + B. Thus, yp0 = 3Ate3t + Ae3t
and yp00 = 9Ate3t + 6Ae3t . Plugging into the differential equation, we get
¡
¢
¡
¢
¡
¢
9Ate3t + 6Ae3t − 5 3Ate3t + Ae3t + 6 Ate3t + B = e3t + 1
Thus:
(9A − 15A + 6A) te3t + (6A − 5A)e3t + 6B = e3t + 1
Thus, we get that A = 1 and B = 1/6. Thus, a particular solution is
yp = te3t + 1/6
Since t = ln x, this is
yp = ln xe3 ln x + 1/6 = x3 ln x + 1/6
Thus, the general solution to the original equation is
y = c1 x2 + c2 x3 + x3 ln x + 1/6
28. Use the method of variation of parameters to show that
Z x
f (s) sin(x − s) ds
y(x) = c1 cos x + c2 sin x +
0
is a general solution to the differential equation
y 00 + y = f (x)
where f (x) is a continuous function on (−∞, ∞). [Hint: Use the trigonometric
identity sin(x − s) = sin x cos s − sin s cos x.]
Answer: The corresponding homogeneous differential equation is y 00 + y 0 = 0, with
auxiliary equation r2 + 1 = 1, with solution r = ±i. Thus, the solutions to the
homogeneous differential equation are yh = c1 cos x + c2 sin x.
We let y1 = cos x and y2 = sin x. Then y10 = − sin x and y20 = cos x. We want to find
a particular solution of the form
yp = v1 cos x + v2 sin x
18
We get the equations:
v10 cos x + v20 sin x = 0
v10 (− sin x) + v20 (cos x) = f (x)
We solve the equations for v10 and v20 using Cramer’s Rule:
¯
¯
¯ 0
¯
sin
x
¯
¯
¯ f (x) cos x ¯
−f (x) sin x
0
¯=
v1 = ¯¯
= −f (x) sin x
¯
cos2 x + sin2 x
¯ cos x sin x ¯
¯ − sin x cos x ¯
¯
¯
¯ cos x
0 ¯¯
¯
¯ − sin x f (x) ¯
¯ = f (x) cos x
v20 = ¯¯
¯
¯ cos x sin x ¯
¯ − sin x cos x ¯
Thus:
Z
v1 =
−f (x) sin x dx
Z
v2 =
f (x) cos x dx
Since we just want to find one particular solutions, we can choose these to be following
integrals:
Z
x
v1 =
−f (s) sin s ds
0
Z
x
v2 =
f (s) cos s ds
0
Thus:
yp = v1 y1 + v2 y2
Z x
Z x
= cos x
−f (s) sin s ds + sin x
f (s) cos s ds
0
0
Z x
=
(−f (s) sin s cos x + f (s) cos s sin x) ds
0
Z x
=
f (s) (sin x cos s − cos x sin s) ds
0
Now, we use the trig identity from the hint, to get
Z x
yp =
f (s) sin(x − s) ds
0
Thus, the general solution is
Z
x
y = c1 cos x + c2 sin x +
f (s) sin(x − s) ds
0
19
© Copyright 2026 Paperzz