﻿ ]> Exercises

# Exercises

1. Use the fourth order Runge-Kutta Method to numerically solve the ODE from t=0 to t=1 with a step size h=1. Then resolve it with a step size h=0.5 and compare the error at y(1). [To compute the error, first find the analytic solution using Maple (See Module x Lesson y)].

 Step h 1 2 1 1 0 1 1 2 1 1.5611 0 1.2494 0.5 2.2177 0.5590 2.4510 1.24861 4.0060 1.5611 3.9932 4 0.1691%
 Step h ${t}_{n}$ 1 2 3 0.5 0.5 0.5 0 0.5 1 0.5 1 1.5 1 1.1289 1.5624 0 0.5312 1.25 0.25 0.8424 1.7116 0.2577 0.8680 1.7635 0.5312 1.2502 2.3451 1.1289 1.5624 2.4412 2.4414 8.1920E-3%
2. Solve this ODE for the given initial conditions have the solution $z\left(t\right)={z}_{0}\mathrm{cos}\left(\omega t\right)$

Code your solution in MATLAB. Write the code to compute a single step's approximation value using the k1, k2, k3, and k4 values and step size. Then, add an iterative loop around that code that controls how many times and for which values this loop iterates.

You can verify this solution by plugging the solution into the ODE and evaluating the derivative. These ODEs have common analytical functions as solutions. If an ODE does not have an analytical solution then a numerical solution must be found. Just as derivatives are numerically approximated by finite differences (rather than infinitesimal differences); so too are functions approximated by a finite set of points $\left({t}_{n},{y}_{n},n=0,1,2,3,...\right)$ rather than a continuous and infinite set of points. If the finite set of points are close enough together, then this is a good approximation to the continuous function.