1
10.20 The user-defined MATLAB function Sys2ODEsRK2(ODE1,ODE2,a,b,h,yINI,zINI)
(Program 10-5), that is listed in the solution of Example 10-7, solves a system of two ODEs by using the
second-order Runge–Kutta method (modified Euler version). Modify the function such that the two ODEs
are entered in one input argument. Similarly, the domain should be entered by using one input argument,
and the two initial conditions entered in one input argument. For function name and arguments use
[t,x,y]=Sys2ODEsModEU(ODEs,ab,h,INI). The input argument ODEs is a name (dummy name
for the function that is imported into Sys2ODEsModEU) for the function that calculates and (the
input arguments of this function are t,x,y, and the output argument is a two-element vector with the val-
ues of and ). The argument ab is a two-element vector that defines the domain of the solution, h is
the step size, and INI is a two-element vector with the initial values for x and y. The output arguments, t,
x, and y, are vectors of the solution.
(a) Use the function Sys2ODEsModEu to solve the system of ODEs in Problem 10.5. Write a MATLAB
program in a script file that solves the system by using . The program should also plot the exact
solution (given in Problem 10.5) and the numerical solution (both in the same figure).
(b) Use the function Sys2ODEsModEu to solve Problem 10.11. Use and plot y vs x.
Solution
The listing of the user-defined function Sys2ODEsModEu is:
function [t, x, y] = Sys2ODEsModEu(ODEs,ab,h,INI)
% Sys2ODEsModEu solves a system of two first-order initial value ODEs using
% second-order Ronge-Kutta method (modified Euler).