Skip to main content
Logo image

Section Chapter 6 Exercises

Exercises Euler’s Method

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{.}\)

2.

Use Euler’s Method to approximate the solution to the initial-value problem,
\begin{align} y'(t) - 2xy(t) = 0 \amp \tag{28}\\ y(0) = 2, \amp \tag{29} \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-valued 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 = 5 + 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} y_1 = 2.98 \)
  2. What is the meaning of your answer in part (a)?
    Solution.
    What is the meaning of your answer in part \ref{Q1a}?
    Answer.
  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.0.5 \\ \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.
    \(\ds x_1 = 1.05 \hspace{0.5cm} \ds x_2 = 1.1, \hspace{0.5cm} y_1 = 3.895 \)
  4. What is the meaning of your answer in part (b)?
    Solution.
    What is the meaning of your answer in part \ref{Q1b}?
    Answer.
  5. Find the analytic solution to the IVP. Use your solution to compare the exact value of \(y(1.1)\) with and 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 identif \(\ds P(x) \) .
    \begin{align*} y' \amp = 2x - 3y + 1 \\ y' + 3y \amp = 2x + 1 \end{align*}
    We can see tha \(\ds P(x) = 3. \) Then we can find the integrating facto \(\ds z \)
    \begin{align*} z \amp = e^{\mbox{an antiderivative o }} \\ \amp = e^{\mbox{an antiderivative o }} \\ \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} \label{eq14-1} \end{align*}
    Now we recall the product rule for derivatives: \(\ds \frac{d}{dx}\Big( f \cdot g \Big) = f\cdot g' + f' \cdot g. \) We note that the two terms on the left hand side of equation (\ref{eq14-1}) are the result of taking the derivative of the product. Hence we can undo the product rule as follows: \(\ds\frac{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 isolat \(\ds y \) . On the right hand side, we will need to use integration by parts. We choos \(\ds u \) an \(\ds dv \) as follows: \(\ds u = 2x+ \hspace{2cm} \ds du \) by taking the derivative o \(\ds u \) an \(\ds v \) by taking the antiderivative o \(\ds dv \) : \(\ds du = 2dx \hspace{2cm} v = \frac{1}{3}e^{3x}. \) 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 o \(\ds C \) .
    \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 fin \(\ds y(1.1): \)
    \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 wer \(\ds y(1.1) \approx 3.8 \) (found using \(\ds h = 0.1 \) ) an \(\ds 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} y(1.1) = 3.9723 \)

4. Basic Euler’s Method.

Consider the initial-valued 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.
    \(\ds 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.
    \(\ds y(0.5) \approx 1.5625 \)
  3. Which of the approximations above do you trust more?
    Solution.
    Which of the approximations above do you trust more?
    Answer.
  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 \) .
    \begin{align*} y(0) \amp = 1 \\ Ae^{0} \amp = 1 \\ A \amp = 1 \end{align*}
    Therefore the solution is \(\ds y = e^x. \) We can use this to find \(\ds y(0.5): \) \(\ds y(0.5) = e^{0.5} = 1.6487. \) Note that the two numerical approximations wer \(\ds y(0.5) \approx 1.5 \) (found usin \(\ds h = 0.5 \) ) an \(\ds y(0.5) \approx 1.5625 \) (found usin \(\ds h = 0.25 \) ). Both are reasonable approximations, but the approximation using the smaller step size is closer to the exact answer.
    Answer.
    \(\ds y = e^x \ds y(0.5) = e^{0.5} = 1.6487 \)
You have attempted of activities on this page.