Question 7.19: ode15s Consider the stiff system in Example 7.16: v.= 790v -...
ode15s
Consider the stiff system in Example 7.16:
\begin{matrix} \overset{.}{v}= 790v- 1590w \\ \overset{.}{w}= 793v- 1593w \end{matrix} subject to \begin{matrix} v_0= v(0)= 1 \\ w_0= w(0)= -1 \end{matrix}Write a MATLAB script that solves the system using ode15s and ode45 and returns a table that includes the solution estimates for v(t) at t=0:0.1:1, as well as the exact solution and the % relative error for both methods at each point. The exact solution was provided in Example 7.16.
disp(' t v15s v45 vExact e_15s e_45')
t = 0:0.1:1; u0 = [1;−1];
f = @(t,u)([790*u(1)−1590*u(2);793*u(1)−1593*u(2)]);
[t,u15s] = ode15s(f,t,u0);
% Values of v are in the first column of u15s
[t,u45] = ode45(f,t,u0);
% Values of v are in the first column of u45
uExact = @(t)([3180/797*exp(−3*t)−2383/797*exp(−800*t);1586/797*exp
(−3*t)−2383/797*exp(−800*t)]);
for i = 1:length(t),
uex(:,i) = uExact(t(i)); % Evaluate exact solution vector at each t
end
for k=1:length(t),
t_coord = t(k);
v15s = u15s(k,1); % Retain the first column of u15s: values of v
v45 = u45(k,1); % Retain the first column of u45: values of v
vExact = uex(1,k); % Retain the exact values of v
e_15s = (vExact - v15s)/vExact*100;
e_45 = (vExact - v45)/vExact*100;
fprintf('%6.2f %11.6f%11.6f %11.6f %11.6f %11.8f\n',t_coord,v15s,
v45,vExact,e_15s,e_45)
end
t v15s v45 vExact e_15s e_45
0.00 1.000000 1.000000 1.000000 0.000000 0.00000000
0.10 2.955055 2.955511 2.955837 0.026464 0.01102274
0.20 2.187674 2.188567 2.189738 0.094262 0.05345813
0.30 1.620781 1.622657 1.622198 0.087342 −0.02830662
0.40 1.201627 1.201785 1.201754 0.010535 −0.00261497
0.50 0.890826 0.890278 0.890281 −0.061233 0.00033632
0.60 0.660191 0.659508 0.659536 −0.099254 0.00427387
0.70 0.489188 0.488525 0.488597 −0.121031 0.01461519
0.80 0.362521 0.361836 0.361961 −0.154754 0.03468108
0.90 0.268708 0.268171 0.268147 −0.209208 −0.00866986
1.00 0.199060 0.198645 0.198649 −0.207140 0.00178337
It is easy to see that even for this stiff system of ODEs, the solver ode45 still outperforms ode15s, which is specially designed to handle such systems.