Navigation

Qualitative methods for differential equations

12.4 Euler's method in spreadsheets

6 problems · hints, answers and solutions shown beside each one

Use a spreadsheet to approximate the solution to the initial value problem

dydt=1y,y(0)=1\diff{y}{t}=\frac{1}{y}\qquad,\qquad y(0)=-1

from t=0t=0 to t=5t=5, using step size Δt=0.05\Delta t = 0.05. Plot the solution.

Answer

Figure from prac_s12.4, line 2

Figure from prac_s12.4, line 2

Full solution

We set up a spreadsheet as below. The first row contains labels.

ABC
1ty\_ky\_k'
20-1=1/B2
3=A2+0.05=B2+C2*0.05\downarrow

We copy the bottom cells down through Row 42, and plot columns A and B.

Figure from prac_s12.4, line 66

Figure from prac_s12.4, line 66

Use a spreadsheet to approximate the solution to the initial value problem

dydt=y24,y(0)=0.4\diff{y}{t}=y^2-4\qquad,\qquad y(0)=0.4

from t=1t=-1 to t=0t=0 with step size 0.10.1. Plot the solution.

Hint

You need to go to the left, as it were, by finding tt-values that are decreasing. That means you'll use Δt=0.1\Delta t = -0.1.

Answer

Figure from prac_s12.4, line 2

Figure from prac_s12.4, line 2

Full solution

Since we're taking values of tt that are decreasing, we'll use Δt=0.1\Delta t = -0.1. Our spreadsheet setup is below. The first row contains labels.

ABC
1ty\_ky\_k'
200.4=B2*B2-4
3=A2-0.1=B2-0.1*C2\downarrow
4\downarrow\downarrow\downarrow

We copy the columns down to Row 12 and plot columns A and B.

Figure from prac_s12.4, line 2

Figure from prac_s12.4, line 2

Use a spreadsheet to approximate the solution to the initial value problem

dydt=1y1+x2,y(0)=0\diff{y}{t}=\frac{1-y}{1+x^2}\qquad,\qquad y(0)=0

from t=10t=-10 to t=10t=10 with step size 0.20.2. Plot the solution.

Hint

You'll be branching out from t=0t=0 in two directions. So, you can copy-paste twice: once with Δt=0.2\Delta t=0.2, and once with Δt=0.2\Delta t = -0.2.

Answer

Figure from prac_s12.4, line 2

Figure from prac_s12.4, line 2

Full solution

We'll set up our spreadsheet twice. First, in the normal way, with initial value y(0)=0y(0)=0 and step size Δt=0.2\Delta t = 0.2. Then, with the same initial value, but Δt=0.2\Delta t = -0.2. The first collection of data will approximate y(t)y(t) to the right of t=0t=0; the second collection will approximate y(t)y(t) to the left of t=0t=0.

So, our spreadsheet looks something like this (note the omitted rows):

ABC
1ty\_ky\_k'
200=(1-B2)/(1+A2*A2)
3=A2+0.2=B2+0.2*C2\downarrow
4\downarrow\downarrow\downarrow
\vdots\vdots\vdots\vdots
52\downarrow\downarrow\downarrow
5300\downarrow
54=A53-0.2=B53-0.2*C53\downarrow
55\downarrow\downarrow\downarrow
\vdots\vdots\vdots\vdots
103\downarrow\downarrow\downarrow

The plot looks something like this:

Figure from prac_s12.4, line 2

Figure from prac_s12.4, line 2

Consider the following spreadsheet setup, where arrows indicate that an entry has been copied down a column, and the first row contains labels.

ABC
1ty\_ky\_k'
210=B2$\wedge$A2+0.2*B2
3=A2+0.01=B2+0.01*C2\downarrow
4\downarrow\downarrow\downarrow

The spreadsheet is approximating a solution to an initial value problem.

  1. What is the initial value?

  2. What is dydt\diff{y}{t}?

  3. What is the step size?

Hint

There's no need to try to find tricks – just interpet the labels in Row 1 at face value.

Answer
  1. y(1)=0y(1)=0

  2. dydt=yt+0.2y\diff{y}{t}=y^t+0.2y

  3. 0.01

Full solution

There are, theoretically, different ways one could interpret the spreadsheet. But, one approach is by far the most obvious: to interpret the labels at face value.

  1. The tt-values are stored in column AA, and the approximate yy-values are stored in Column B. The only ones that are entered as numbers (as opposed to computed) are in cells A2 and B2. So, the initial value is y(1)=0y(1)=0.

  2. Derivatives are computed in column C. The cell A2 references the tt-value, and the cell B2 references the yy-value. So, we interpret the entry in cell C2 to mean dydt=yt+0.2y\diff{y}{t} = y^t+0.2y.

  3. The step size is recognizable in two places. In Column A, we see that the tt-values go up by 0.01 each step, so Δt=0.01\Delta t = 0.01. This also accords with the formula in Column B:

    yk+1=ykB2+Δt0.01ykC2y_{k+1} = \underbrace{y_k}_{\text{B2}}+\underbrace{\Delta t}_{0.01} \cdot \underbrace{y_k'}_{\text{C2}}

In this question, we'll investigate step size and error. We'll use the initial value problem

dydt=2xy2,y(0)=1 .\diff{y}{t} =-2xy^2 \qquad,\qquad y(0)=1~.
  1. Use a spreadsheet to approximate y(1)y(1), using a step size Δt=0.1\Delta t = 0.1. Store the step size in its own cell, so that it can be changed later.

  2. The actual value of y(1)y(1) (which you don't know how to find on your own yet) is 12\frac12. Change the value of Δt\Delta t until your approximation of y(1)y(1) is within 0.001 of the actual value. What value of Δt\Delta t is small enough to keep the error within this tolerance?

Hint

The values of Δt\Delta t must be of the form 1n\frac1n, where nn is a whole number; otherwise, you won't get an approximation for y(1)y(1) specifically.

Answer
  1. y(1)0.503641976y(1) \approx 0.503641976

  2. Δt\Delta t can be no bigger than 136\frac{1}{36}

Full solution
  1. Our spreadsheet setup is as follows:

    ABCD
    1ty\_ky\_k'step
    201=-2*A2*B2*B20.1
    3=A2+\$D\$2=B2+\$D\$2*C2\downarrow
    4\downarrow\downarrow\downarrow

    Cel B12 holds the approximation y(1)0.503641976y(1) \approx 0.503641976.

  2. We copy columns A, B and C down the spreadsheet further, so that we will still be able to see the row holding t=1t=1 after we make the entry in D2 smaller. We want to approximate y(1)y(1), so our value of Δt\Delta t should have the form 1n\frac1n, for a whole number nn. (Then our approximation will take nn steps of Euler's method.)

    By trial and error, we find that Δt=135\Delta t = \frac1{35} gives us the approximation y(1)0.501024233y(1) \approx 0.501024233 (in cell B37), and Δt=136\Delta t= \frac1{36} gives us the approximation y(1)0.500995477y(1) \approx 0.500995477 (in cell B38). So, Δt=135\Delta t =\frac{1}{35} is too large, but Δt=136\Delta t= \frac{1}{36} is small enough. Taking even smaller values of Δt\Delta t keeps our approximation within the given error tolerance. So, any value of Δt\Delta t that is no bigger than 136\frac{1}{36} will do.

Consider the initial value problem

dydt=11y2,y(0)=0.1 .\diff{y}{t}=\frac{1}{1-y^2}\qquad,\qquad y(0)=-0.1~.

We want to know when yy will be equal to 0. Using a spreadsheet and Euler's method, approximate the root of yy.

Hint

You aren't given an error tolerance, so it's up to you to play around with step sizes until your answers seems relatively consistent.

Answer

You aren't given an error tolerance, so your actual answer may vary, but if you've done a good job of making your step size relatively small, then your approximation should be relatively close to the actual answer of 11013000=0.09966\frac1{10}-\frac1{3000}=0.099\overline{66}.

This question is meant to get you thinking about how to use spreadsheets creatively, but the vagueness makes it unlikely to show up on an exam in exactly this form.

Full solution

We'll start with a fairly usual setup. We'll keep the step size stored separately, so we can change it later. Instead of copying our values down the column until we find a particular tt-value, we're looking for a particular yy-value. Or, at least, the spot where the yky_k values change from negative to positive.

ABCD
1ty\_ky\_k'step
20-0.1=1/(1-B2*B2)0.1
3=A2+\$D\$2=B2+\$D\$2*C2\downarrow
4\downarrow\downarrow\downarrow

The first iteration of Euler's method with step size 0.1 approximates y(0.1)>0y(0.1)>0. So, this approximation puts the root somewhere between 0 and 0.1 (but remember, it might not be entirely accurate).

Next, we will increase our accuracy by decreasing our step size. Changing the value in D2 to 0.1, and copying further down the columns, shows us y(0.09)0.00961562y(0.09) \approx-0.00961562 and y(0.1)0.000385304y(0.1)\approx0.000385304. So, this approximation guesses the root is between 0.090.09 and 0.10.1. We continue to decrease Δt\Delta t and note the tt-values where the corresponding approximation changes from negative to positive.

Δt\Delta tlower boundupper bound
0.100.1
0.010.090.1
0.0010.0990.1
0.00010.09960.0997

There's not a clear stopping point, but the last approximation required about 1000 rows of the spreadsheet to produce, which seems on the edge of what is reasonable. So, our guess for the root is, let's say, 0.099650.09965.

Source

This section is original content.

From the UBC Math 100 open textbook project, © Joel Feldman, Andrew Rechnitzer, Elyse Yeager and others. Licensed CC BY-NC-SA 4.0; this HTML adaptation is released under the same licence. Full attribution.