Exercise 16.2

Exercise 16.2#

Write a program that solves the differential equation:

\[ \frac{dy}{dx} = \frac{1}{1 + x^2} \]

where y = 1 at x = 0.

Question 1#

Using Euler’s method with a chosen step size of h = 0.1, calculate each \((x_n, y_n)\) until you reach \(x = 1.0\). And plot this solution.

Question 2#

The exact solution for this method is:

\[ y = 1 + \arctan(x) \]

Plot this alongside your numerical solution as a visual check.

Question 3#

Now calculate and plot the absolute values of the differences between the Euler’s method and analytic solution at \(x = 1\) using step sizes of:

  • \(h = 0.1\)

  • \(h = 0.08\)

  • \(h = 0.06\)

  • \(h = 0.004\)

  • \(h = 0.002\)

what trend do you notice?