1
10.16 Write a user-defined MATLAB function that solves a first-order ODE by applying the midpoint
method (use the form of second-order Runge–Kutta method, Eqs. (10.65), (10.66)). For function name and
arguments use [x,y]=odeMIDPOINT(ODE,a,b,h,yINI). The input argument ODE is a name for
the function that calculates . It is a dummy name for the function that is imported into odeMIDPOINT.
The arguments a and b define the domain of the solution, h is the step size, and yINI is the initial value.
The output arguments, x and y, are vectors with the x and y coordinates of the solution.
Use the function odeMIDPOINT to solve the ODE in Problem 10.2. Write a MATLAB program in a
script file that solves the ODE twice, once by using and once by using . The program
should also plot the exact solution (given in Problem 10.2) and plot the two numerical solutions (all in the
same figure).
Solution
The listing of the user-defined function odeMIDPOIN is:
function [x, y] = odeMIDPOINT(ODE,a,b,h,yINI)
% odeMIDPOINT solves a first order initial value ODE using the