Skip to main content
Logo image

Section 8.4 Exercises

πŸ“: Note on Variables.

Exercises ✍🏻 Problems

1.

Approximate the solution to the differential equation
\begin{equation*} y' = y^2 - x, \quad y(0) = -1 \end{equation*}
over the interval \([0, 1]\) with a step size of \(h = 0.5\text{.}\)
Hint.
Start with the given initial condition \(y_0 = -1\) at \(x_0 = 0\text{.}\) Use Euler’s update formula: \(y_{k+1} = y_k + h \cdot f(x_k, y_k)\text{,}\) where \(f(x, y) = y^2 - x\text{.}\) You’ll need to compute two steps to reach \(x = 1\text{.}\)

2.

Use Euler’s Method to approximate the solution to the initial-value problem,
\begin{align} y'(x) - 2x y(x) = 0 \amp \tag{8.5}\\ y(0) = 2, \amp \tag{8.6} \end{align}
at the \(x\)-values \(0,\ 0.5,\ 1,\ 1.5,\ 2\) (spaced 0.5 apart).

3. Basic Euler’s Method.

Consider the initial-value problem
\begin{equation*} y' = 2x - 3y + 1,\quad y(1) = 5 \end{equation*}
and answer the following:
  1. Compute 2 iterations of Euler’s method using step size \(h = 0.1\text{.}\)
    Solution.
    \begin{align*} \mbox{Preliminaries: } \amp \amp f(x,y) \amp = 2x - 3y + 1 \\ \amp \amp h \amp = 0.1 \\ \amp \amp x_0 \amp = 1 \\ \amp \amp y_0 \amp = 5 \\ \amp \amp \amp \mbox{Iteration 1:} \amp \amp x_1 \amp = x_0 + h \\ \amp \amp \amp = 1 + 0.1 \\ \amp \amp \amp = 1.1 \\ \amp \amp y_1 \amp = y_0 + h\cdot f(x_0,y_0) \\ \amp \amp \amp = 5 + 0.1 \cdot f(1,5) \\ \amp \amp \amp = 5 + 0.1 \cdot [2(1) - 3(5) + 1] \\ \amp \amp \amp = 3.8 \\ \amp \amp \amp \mbox{Iteration 2:} \amp \amp x_2 \amp = x_1 + h \\ \amp \amp \amp = 1.1 + 0.1 \\ \amp \amp \amp = 1.2 \\ \amp \amp y_2 \amp = y_1 + h\cdot f(x_1,y_1) \\ \amp \amp \amp = 3.8 + 0.1 \cdot f(1.1,3.8) \\ \amp \amp \amp = 3.8 + 0.1 \cdot [2(1.1) - 3(3.8) + 1] \\ \amp \amp \amp = 2.98 \end{align*}
    %
    Answer.
    \(\ds x_1 = 1.1 \hspace{0.5cm} \ds x_2 = 1.2, \hspace{0.5cm} \ds y_1 = 3.8, \hspace{0.5cm} \ds y_2 = 2.98 \)
  2. What is the meaning of your answer in part (a)?
  3. Compute 2 iterations of Euler’s method using step size \(\ds h = 0.05\text{.}\)
    Solution.
    \begin{align*} \mbox{Preliminaries: } \amp \amp f(x,y) \amp = 2x - 3y + 1 \\ \amp \amp h \amp = 0.05 \\ \amp \amp x_0 \amp = 1 \\ \amp \amp y_0 \amp = 5 \\ \amp \amp \amp \mbox{Iteration 1:} \amp \amp x_1 \amp = x_0 + h \\ \amp \amp \amp = 1 + 0.05 \\ \amp \amp \amp = 1.05 \\ \amp \amp y_1 \amp = y_0 + h\cdot f(x_0,y_0) \\ \amp \amp \amp = 5 + 0.05 \cdot f(1,5) \\ \amp \amp \amp = 5 + 0.05 \cdot [2(1) - 3(5) + 1] \\ \amp \amp \amp = 4.4 \\ \amp \amp \amp \mbox{Iteration 2:} \amp \amp x_2 \amp = x_1 + h \\ \amp \amp \amp = 1.05 + 0.05 \\ \amp \amp \amp = 1.1 \\ \amp \amp y_2 \amp = y_1 + h\cdot f(x_1,y_1) \\ \amp \amp \amp = 4.4 + 0.05 \cdot f(1.05,4.4) \\ \amp \amp \amp = 4.4 + 0.05 \cdot [2(1.05) - 3(4.4) + 1] \\ \amp \amp \amp = 3.895 \end{align*}
    Answer.
    \(x_1 = 1.05 \hspace{0.5cm} x_2 = 1.1, \hspace{0.5cm} y_1 = 4.4, \hspace{0.5cm} y_2 = 3.895 \)
  4. What is the meaning of your answer in part (b)?
  5. Find the analytic solution to the IVP. Use your solution to compare the exact value of \(y(1.1)\) with your answers from parts (a) and (b).
    Solution.
    This DE is first-order and linear, so we can solve it using an integrating factor. (There are other solution techniques, as well.)
    We begin by putting the DE in the standard form for a first-order linear DE so that we can identify \(\ds P(x) \text{.}\)
    \begin{align*} y' \amp = 2x - 3y + 1 \\ y' + 3y \amp = 2x + 1 \end{align*}
    We can see that \(\ds P(x) = 3.\) Then we can find the integrating factor \(\ds z \)
    \begin{align*} z \amp = e^{\mbox{an antiderivative of P(x)}} \\ \amp = e^{\mbox{an antiderivative of 3}} \\ \amp = e^{3x} \end{align*}
    Now we multiply both sides of the DE by the integrating factor.
    \begin{align*} e^{3x}\cdot y' + 3e^{3x}y \amp = (2x+1)e^{3x} \nonumber \\ \underbrace{e^{3x}}_{f}\cdot\underbrace{y'}_{g'} + \underbrace{3e^{3x}}_{f'}\cdot\underbrace{y}_{g} \amp = (2x+1)e^{3x} \end{align*}
    Now we recall the product rule for derivatives: \(\dfrac{d}{dx}\Big( f \cdot g \Big) = f\cdot g' + f' \cdot g\text{.}\) We note that the two terms on the left-hand side of the equation are the result of taking the derivative of the product. Hence we can undo the product rule as follows: \(\dfrac{d}{dx}\Big(e^{3x}\cdot y \Big) = (2x+1)e^{3x}.\) We would like to integrate both sides of the equation so we can isolate \(y\text{.}\) On the right-hand side, we will need to use integration by parts. We choose \(u\) and \(dv\) as follows: \(u = 2x+1 \hspace{2cm} dv = e^{3x}\ dx \hspace{2cm} du\) by taking the derivative of \(u\) and \(v\) by taking the antiderivative of \(dv\) : \(du = 2dx \hspace{2cm} v = \frac{1}{3}e^{3x}\text{.}\) Now we proceed by integrating as follows:
    \begin{align*} \int \frac{d}{dx}\Big(e^{3x}\cdot y \Big)dx \amp = \int (2x+1)e^{3x} dx \\ e^{3x}\cdot y \amp = (2x+1)\cdot\frac{1}{3}e^{3x} - \int \frac{1}{3}e^{3x} \cdot 2dx \\ \amp = \frac{1}{3}(2x+1)e^{3x} - \frac{2}{3}\int e^{3x}dx \\ \amp = \frac{1}{3}(2x+1)e^{3x} - \frac{2}{3}\cdot \frac{1}{3}e^{3x} + C \\ \amp = \frac{2}{3}xe^{3x} + \frac{1}{3}e^{3x} - \frac{2}{9}e^{3x} + C \\ \amp = \frac{2}{3}xe^{3x} + \frac{1}{9}e^{3x} + C \\ y \amp = \frac{2}{3}x + \frac{1}{9} + \frac{C}{e^{3x}} \\ \amp = \frac{2}{3}x + \frac{1}{9} + Ce^{-3x} \end{align*}
    Now we use the initial condition to find the value of \(\ds C \text{.}\)
    \begin{align*} y(1) \amp = 5 \\ \frac{2}{3}\cdot 1 + \frac{1}{9} + Ce^{-3\cdot 1} \amp = 5 \\ \frac{7}{9} + Ce^{-3} \amp = 5 \\ Ce^{-3} \amp = \frac{38}{9} \\ C \amp = \frac{38}{9e^{-3}} \\ \amp = \frac{38e^3}{9} \end{align*}
    Hence, the solution is \(\ds y = \frac{2}{3}x + \frac{1}{9} + \frac{38e^3}{9}e^{-3x}. \) We can use this to find \(\ds y(1.1)\text{:}\)
    \begin{align*} y(1.1) \amp = \frac{2}{3}\cdot 1.1 + \frac{1}{9} + \frac{38e^3}{9}e^{-3\cdot 1.1} \\ \amp = 3.9723 \end{align*}
    Note that the two numerical approximations were \(\ds y(1.1) \approx 3.8 \) (found using \(h = 0.1 \)) and \(y(1.1) \approx 3.895 \) (found using \(\ds h = 0.05 \)). Both are reasonable approximations, but the approximation using the smaller step size is closer to the exact answer.
    Answer.
    \(\ds y = \frac{2}{3}x + \frac{1}{9} + \frac{38e^3}{9}e^{-3x},\quad y(1.1) \approx 3.9723 \)

4. Basic Euler’s Method.

Consider the initial-value problem
\begin{equation*} y' = y,\quad y(0) = 1 \end{equation*}
and answer the following:
  1. Use Euler’s method to approximate \(y(0.5)\) using step size \(\ds h = 0.5\text{.}\)
    Solution.
    \begin{align*} \mbox{Preliminaries: } \amp \amp f(x,y) \amp = y \\ \amp \amp h \amp = 0.5 \\ \amp \amp x_0 \amp = 0 \\ \amp \amp y_0 \amp = 1 \\ \amp \amp \amp \mbox{Iteration 1:} \amp \amp x_1 \amp = x_0 + h \\ \amp \amp \amp = 0 + 0.5 \\ \amp \amp \amp = 0.5 \\ \amp \amp y_1 \amp = y_0 + h\cdot f(x_0,y_0) \\ \amp \amp \amp = 1 + 0.5 \cdot f(0,1) \\ \amp \amp \amp = 1 + 0.5 \cdot [1] \\ \amp \amp \amp = 1.5 \end{align*}
    Hence \(\ds y(0.5) \approx 1.5. \)
    Answer.
    \(y(0.5) \approx 1.5 \)
  2. Use Euler’s method to approximate \(y(0.5)\) using step size \(h = 0.25\text{.}\)
    Solution.
    \begin{align*} \mbox{Preliminaries: } \amp \amp f(x,y) \amp = y \\ \amp \amp h \amp = 0.25 \\ \amp \amp x_0 \amp = 0 \\ \amp \amp y_0 \amp = 1 \\ \amp \amp \amp \mbox{Iteration 1:} \amp \amp x_1 \amp = x_0 + h \\ \amp \amp \amp = 0 + 0.25 \\ \amp \amp \amp = 0.25 \\ \amp \amp y_1 \amp = y_0 + h\cdot f(x_0,y_0) \\ \amp \amp \amp = 1 + 0.25 \cdot f(0,1) \\ \amp \amp \amp = 1 + 0.25 \cdot [1] \\ \amp \amp \amp = 1.25 \\ \amp \amp \amp \mbox{Iteration 2:} \amp \amp x_2 \amp = x_1 + h \\ \amp \amp \amp = 0.25 + 0.25 \\ \amp \amp \amp = 0.5 \\ \amp \amp y_2 \amp = y_1 + h\cdot f(x_1,y_1) \\ \amp \amp \amp = 1.25 + 0.25 \cdot f(0.25,1.25) \\ \amp \amp \amp = 1.25 + 0.25 \cdot [1.25] \\ \amp \amp \amp = 1.5625 \end{align*}
    Hence \(\ds y(0.5) \approx 1.5625. \)
    Answer.
    \(y(0.5) \approx 1.5625 \)
  3. Which of the approximations above do you trust more?
  4. Find the analytic solution to the IVP. Use it to compute the exact value of \(y(0.5)\) and compare with your answers from parts (a) and (b).
    Solution.
    There are multiple solution techniques that will work to solve this DE. We will separate variables here.
    \begin{align*} y' \amp = y \\ \frac{dy}{dx} \amp = y \\ \frac{1}{y}dy \amp = dx \\ \int \frac{1}{y}dy \amp = \int dx \\ \ln|y| \amp = x+C \\ |y| \amp = e^{x+C} \\ y \amp = \pm e^C e^x \\ \amp = Ae^x \end{align*}
    Now we can apply the initial condition to find the value of the constant \(\ds A \text{.}\)
    \begin{align*} y(0) \amp = 1 \\ Ae^{0} \amp = 1 \\ A \amp = 1 \text{.} \end{align*}
    Therefore, the solution is \(y = e^x. \) We can use this to find \(y(0.5): y(0.5) = e^{0.5} = 1.6487\text{.}\) Note that the two numerical approximations were \(y(0.5) \approx 1.5 \) (found using \(h = 0.5\)) and \(y(0.5) \approx 1.5625 \) (found using \(h = 0.25 \)). Both are reasonable approximations, but the approximation using the smaller step size is closer to the exact answer.
    Answer.
    \(y = e^x,\quad y(0.5) \approx e^{0.5} \approx 1.6487\)

5. Comparing Step Sizes.

Consider the initial-value problem
\begin{equation*} y' = -y, \quad y(0) = 1 \end{equation*}
on the interval \([0, 1]\text{.}\)
  1. Use Euler’s method with step size \(h = 0.5\) to approximate \(y(1)\text{.}\)
    Solution.
    \begin{align*} \mbox{With } h = 0.5\text{:} \amp \\ y_0 \amp = 1 \\ y_1 \amp = y_0 + 0.5(-y_0) = 1 + 0.5(-1) = 0.5 \\ y_2 \amp = y_1 + 0.5(-y_1) = 0.5 + 0.5(-0.5) = 0.25 \end{align*}
    Thus, \(y(1) \approx 0.25\text{.}\)
    Answer.
    \(y(1) \approx 0.25\)
  2. Use Euler’s method with step size \(h = 0.25\) to approximate \(y(1)\text{.}\)
    Solution.
    \begin{align*} \mbox{With } h = 0.25\text{:} \amp \\ y_0 \amp = 1 \\ y_1 \amp = y_0 + 0.25(-y_0) = 1 - 0.25 = 0.75 \\ y_2 \amp = y_1 + 0.25(-y_1) = 0.75 - 0.1875 = 0.5625 \\ y_3 \amp = y_2 + 0.25(-y_2) = 0.5625 - 0.140625 = 0.421875 \\ y_4 \amp = y_3 + 0.25(-y_3) \approx 0.421875 - 0.105469 = 0.316406 \end{align*}
    Thus, \(y(1) \approx 0.316\text{.}\)
    Answer.
    \(y(1) \approx 0.316\)
  3. The exact solution is \(y(t) = e^{-t}\text{.}\) Calculate \(y(1)\) exactly and compare with your approximations from parts (a) and (b). Which approximation is closer to the true value?
    Solution.
    The exact value is \(y(1) = e^{-1} \approx 0.368\text{.}\) The approximation with \(h = 0.25\) gives \(0.316\text{,}\) which is closer to \(0.368\) than the approximation with \(h = 0.5\text{,}\) which gives \(0.25\text{.}\) This demonstrates that smaller step sizes generally produce more accurate results.
    Answer.
    \(y(1) = e^{-1} \approx 0.368\text{;}\) the smaller step size \(h = 0.25\) gives a more accurate approximation.

6. Conceptual Understanding.

Answer the following questions about Euler’s method:
  1. Why does decreasing the step size \(h\) generally improve the accuracy of Euler’s method? Explain in terms of the geometry of the solution curve.
  2. Suppose you’re using Euler’s method and notice that your approximation seems to drift further from the true solution as you take more steps. What might be happening, and what could you do to improve the approximation?
  3. Can Euler’s method produce the exact solution for any differential equation? If so, give an example. If not, explain why not.
You have attempted of activities on this page.