Euler's method to solve an IVP (step halving)

This is to be done with students working side-by-side in pairs. Discuss and share!

The problem

If y(t) satisfies the differential equation dy/dt = cos y + y sin t, and additionally y(0) = 1, determine y(4.5) to an accuracy of ±0.005 using Euler's method (implemented in Python).

The method

Here is an implementation of Euler's method in Python, which I wrote and you can copy. Note that the particulars in the code below are different from those of the problem you're asked to solve: you'll need to adapt it to your problem.

lab3_euler_s25_code.png

How to estimate the error

To get an estimate of the error in your Euler approximation, you can halve the step size and take the difference in your two approximations for y(4.5) as an estimate of the error of the better approximation. If that diffference is greater than 0.005, then you'll need to halve again, etc.

In a spreadsheet or on a piece of paper, make a table showing how your estimate of y(4.5) depends on the step size you use.

Your final answer should look something like y(4.5) = 23.459 ± 0.002, or 23.456 < y(4.5) < 23.463 (but with different numbers). The best approximation to the exact answer (without doing more Euler runs) is your best Euler result (the one using the smallest steps) plus the difference between this result and the result with half as many steps.

euler_stopping_criterion.png

Ask your TA to check your work.

Checklist for TA

Note to self

For next time, increase the spacing of the slopefield lines to .5 so that the students' code runs quicker when the vertical range is expanded.