At Mark 22: | nwkjac and njcpvt were removed from the interface; neq was made optional |
. . . [...] = d02nv(...); [...] = d02nt(...); [..., ifail] = d02nh(...); if (ifail ~= 1 and ifail < 14) [...] = d02ny(...); end . . .The linear algebra setup function nag_ode_ivp_stiff_bandjac_setup (d02nt) and one of the integrator setup functions, nag_ode_ivp_stiff_dassl (d02mv), nag_ode_ivp_stiff_bdf (d02nv) or nag_ode_ivp_stiff_blend (d02nw), must be called prior to the call of nag_ode_ivp_stiff_imp_bandjac (d02nh). The integrator diagnostic function nag_ode_ivp_stiff_integ_diag (d02ny) may be called after the call to nag_ode_ivp_stiff_imp_bandjac (d02nh). There is also a function, nag_ode_ivp_stiff_contin (d02nz), designed to permit you to change step size on a continuation call to nag_ode_ivp_stiff_imp_bandjac (d02nh) without restarting the integration process.
Input Parameters
Output Parameters
(1) |
(2) |
Input Parameters
Output Parameters
for i = 1:neq j1 = max(i-ml,1); j2 = min(i+mu,neq); for j = j1:j2 k = min(ml+1-i,0)+j; p(k,i) = δr/δy(i,j); end endSee also the function document for nag_lapack_dgbtrf (f07bd).
Input Parameters
[errloc, ifail] = d02za(acor(1:neq,2), acor(1:neq,1)); % Check ifail before proceeding
Output Parameters
Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.
Open in the MATLAB editor: d02nh_example
function d02nh_example fprintf('d02nh example results\n\n'); neq = int64(3); maxord = int64(5); sdysav = maxord+1; petzld = false; tcrit = 0; hmin = 1.0e-10; hmax = 10; h0 = 0; maxstp = int64(200); mxhnil = int64(5); const = zeros(6, 1); rwork = zeros(50+4*neq, 1); % Setup for d02nh. [const, rwork, ifail] = d02nv( ... neq, sdysav, maxord, 'Newton', petzld, ... const, tcrit, hmin, hmax, h0, maxstp, ... mxhnil, 'Average-L2', rwork); ml = int64(1); mu = int64(2); nwkjac = int64(neq*(2*ml+mu+1)); % Numerical Jacobian [rwork, ifail] = d02nt( ... neq, neq, 'Numerical', ml, mu, nwkjac, neq, rwork); % Initialize variables and arrays for integration t = 0; tout = 10; y = [1; 0; 0]; ydot = zeros(neq, 1); rtol = [0.0001]; atol = [1e-06; 1e-07; 1e-06]; itol = int64(2); inform(1:23) = int64(0); ysave = zeros(neq, sdysav); wkjac = zeros(nwkjac, 1); jacpvt(1:neq) = int64(0); lderiv = [false; true]; itask = int64(6); itrace = int64(0); % Solve for the initial values y and dy/dx as check [t, tout, y, ydot, rwork, inform, ysave, wkjac, jacpvt, lderiv, ifail] = ... d02nh( ... t, tout, y, ydot, rwork, rtol, atol, itol, inform, @resid, ysave, ... 'd02nhz', wkjac, jacpvt, 'd02nby', lderiv, itask, itrace); fprintf ('Initial y : %8.4f %8.4f %8.4f\n',y); fprintf ('Initial ydot: %8.4f %8.4f %8.4f\n',ydot); % Use these initial estimates and integrate to tout % (overshoot and interpolate) itask = int64(1); tout = 10; [t, tout, y, ydot, rwork, inform, ysave, wkjac, jacpvt, lderiv, ifail] = ... d02nh( ... t, tout, y, ydot, rwork, rtol, atol, itol, inform, @resid, ysave, ... 'd02nhz', wkjac, jacpvt, 'd02nby', lderiv, itask, itrace); fprintf ('\n x y\n'); fprintf ('%8.3f %13.5f %13.5f %13.5f\n',tout,y); [hu, h, tcur, tolsf, nst, nre, nje, nqu, nq, niter, imxer, algequ, ifail] = ... d02ny( ... neq, neq, rwork, inform); fprintf('\nDiagnostic information\n integration status:\n'); fprintf(' last and next step sizes = %8.5f, %8.5f\n',hu, h); fprintf(' integration stopped at x = %8.5f\n',tcur); fprintf(' algorithm statistics:\n'); fprintf(' number of time-steps and Newton iterations = %5d %5d\n', ... nst,niter); fprintf(' number of residual and jacobian evaluations = %5d %5d\n', ... nre,nje); fprintf(' order of method last used and next to use = %5d %5d\n', ... nqu,nq); fprintf(' component with largest error = %5d\n',imxer); function [f, ires] = fcn(neq, t, y, ires) % Evaluate derivative vector. f = zeros(3,1); f(1) = -0.04*y(1) + 10000*y(2)*y(3); f(2) = 0.04*y(1) - 10000*y(2)*y(3) - 30000000*y(2)*y(2); f(3) = 30000000*y(2)*y(2); function p = jac(neq, t, y, h, d, p) % Evaluate the Jacobian. p = zeros(neq, neq); hxd = h*d; p(1,1) = 1 - hxd*(-0.04); p(1,2) = -hxd*(10000*y(3)); p(1,3) = -hxd*(10000*y(2)); p(2,1) = -hxd*(0.04); p(2,2) = 1 - hxd*(-10000*y(3)-60000000*y(2)); p(2,3) = -hxd*(-10000*y(2)); p(3,2) = -hxd*(60000000*y(2)); p(3,3) = 1 - hxd*(0); function [r, ires] = resid(neq, t, y, ydot, ires) r = zeros(neq,1); r(1) = -ydot(1) - ydot(2) - ydot(3); r(2) = -ydot(2); r(3) = -ydot(3); if (ires == 1) ; r(1) = 0.0d0 + r(1); r(2) = 0.04d0*y(1) - 1.0d4*y(2)*y(3) - 3.0d7*y(2)*y(2) + r(2); r(3) = 3.0d7*y(2)*y(2) + r(3); end ;
d02nh example results Initial y : 1.0000 0.0000 0.0000 Initial ydot: -0.0400 0.0400 0.0000 Warning: Equation(=i1) and possibly other equations are implicit and in calculating the initial values the equations will be treated as implicit. In above message i1 = 1 x y 10.000 0.84135 0.00002 0.15863 Diagnostic information integration status: last and next step sizes = 0.94084, 0.94084 integration stopped at x = 10.25785 algorithm statistics: number of time-steps and Newton iterations = 48 66 number of residual and jacobian evaluations = 119 15 order of method last used and next to use = 4 4 component with largest error = 3