. . . % Initialize the integrator [...] = d02mw(...); % Is the Jacobian matrix banded? if (banded) [...] = d02np(...); end % Set DT to the required temporal resolution % Set TEND to the final time % Call the integrator for each temporal value while 1 [tout,...] = d02ne(...); if (tout>=tend || itask<0) break end if (itask ~= 1) tout = min(tout + dt, tend); end % Print the solution [...] = d02mc(...); end . . .
Input Parameters
Output Parameters
Input Parameters
Output Parameters
Open in the MATLAB editor: d02ne_example
function d02ne_example fprintf('d02ne example results\n\n'); fprintf('Example 1\n'); ex1; fprintf('\nExample 2\n'); ex2; function ex1 % Stiff Robertson problem % Initialize the problem, specifying that the Jacobian is to be % evaluated analytically using the provided routine jac. neq = int64(3); maxord = int64(5); jceval = 'Analytic'; hmax = 0; h0 = 0; itol = int64(1); lcom = int64(200); [icom, com, ifail] = d02mw(... neq, maxord, jceval, hmax, h0, itol, lcom); % Specify that the Jacobian is banded mu = int64(2); ml = int64(1); [icom, ifail] = d02np(neq, ml, mu, icom); % Set initial values rtol = [1e-3; 1e-3; 1e-3]; atol = [1e-6; 1e-6; 1e-6]; y = [1; 0; 0]; ydot = zeros(neq,1); t = 0; tout = 0.02; % Use the user parameter to pass the band dimensions through to jac. % An alternative would be to hard code values for ml and mu in jac. user = {ml, mu}; fprintf('\n t y\n'); fprintf('%8.4f %12.6f %12.6f %12.6f\n', t, y); itask = int64(0); % Obtain the solution at 5 equally spaced values of T. for j = 1:5 if ifail == 0 [t, y, ydot, rtol, atol, itask, icom, com, user, ifail] = ... d02ne(... t, tout, y, ydot, rtol, atol, itask, @res1, @jac1, ... icom, com, 'user', user); fprintf('%8.4f %12.6f %12.6f %12.6f\n', t, y); tout = tout + 0.02; icom = d02mc(icom); end end fprintf('\nThe integrator completed task, ITASK = %d\n', itask); function ex2 % Setup neq = int64(1); maxord = int64(5); jceval = 'Analytic'; hmax = 0; h0 = 0; itol = int64(1); lcom = int64(200); [icom, com, ifail] = d02mw(... neq, maxord, jceval, hmax, h0, itol, lcom); % Set initial values rtol = [0]; atol = [1e-8]; t = 0; tout = 0.2; y = [2]; ydot = [0]; fprintf('\n t y\n'); fprintf('%8.4f %12.6f\n', t, y); itask = int64(0); % Obtain the solution at 5 equally spaced values on continuation path. for j = 1:5 if ifail == 0 [t, y, ydot, rtol, atol, itask, icom, com, user, ifail] = ... d02ne(... t, tout, y, ydot, rtol, atol, itask, @res2, @jac2, ... icom, com); fprintf('%8.4f %12.6f\n', t, y); tout = tout + 0.2; icom = d02mc(icom); end end fprintf('\nThe integrator completed task, ITASK = %d\n', itask); function [pd, user] = jac1(neq, t, y, ydot, pd, cj, user) ml = user{1}; mu = user{2}; stride = 2*ml+mu+1; % Main diagonal pdfull(i,i), i=1,neq md = mu + ml + 1; pd(md) = -0.04 - cj; pd(md+stride) = -1.0e4*y(3) - 6.0e7*y(2) - cj; pd(md+2*stride) = -cj; % 1 sub-diagonal pdfull(i+1:i), i=1,neq-1 ms = md + 1; pd(ms) = 0.04; pd(ms+stride) = 6.0e7*y(2); % First super-diagonal pdfull(i-1,i), i=2, neq ms = md - 1; pd(ms+stride) = 1.0e4*y(3); pd(ms+2*stride) = -1.0e4*y(2); % Second super-diagonal pdfull(i-2,i), i=3, neq ms = md - 2; pd(ms+2*stride) = 1.0e4*y(2); function [r, ires, user] = res1(neq, t, y, ydot, ires, user) r = zeros(neq, 1); r(1) = -0.04*y(1) + 1.0e4*y(2)*y(3) - ydot(1); r(2) = 0.04*y(1) - 1.0e4*y(2)*y(3) - 3.0e7*y(2)*y(2) - ydot(2); r(3) = 3.0e7*y(2)*y(2) - ydot(3); function [pd, user] = jac2(neq, t, y, ydot, pd, cj, user) pd(1) = -2*y(1) + 0.1*t*y(1)*exp(y(1)); function [r, ires, user] = res2(neq, t, y, ydot, ires, user) r(1) = 4 - y(1)^2 + t*0.1*exp(y(1));
d02ne example results Example 1 t y 0.0000 1.000000 0.000000 0.000000 0.0200 0.999204 0.000036 0.000760 0.0400 0.998415 0.000036 0.001549 0.0600 0.997631 0.000036 0.002333 0.0800 0.996852 0.000036 0.003112 0.1000 0.996080 0.000036 0.003884 The integrator completed task, ITASK = 3 Example 2 t y 0.0000 2.000000 0.2000 2.038016 0.4000 2.078379 0.6000 2.121462 0.8000 2.167736 1.0000 2.217821 The integrator completed task, ITASK = 3