You will test Euler's method on a linear equation whose exact answer comes from the integrating factor. The equation is for , with at .
The idea. The integrating factor is , so and . The point gives . The exact solution is . Euler's method takes small steps along the slope, and its error should shrink when the steps get smaller.
Your tasks.
f(x, y). It returns the slope written as a function of and .euler(x0, y0, x_end, n). Take equal steps of size . In each step, add to y, and add h to x.error(n). Return the size of the gap between Euler's answer and the exact answer at , with steps from .Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…