At Mark 22: | nwkjac and njcpvt were removed from the interface; neq was made optional |
. . . [...] = d02nv(...); [...] = d02nu(...); [..., ifail] = d02nj(...); if (ifail ~= 1 and ifail < 14) [...] = d02nx(...); [...] = d02ny(...); end . . .The linear algebra setup function nag_ode_ivp_stiff_sparjac_setup (d02nu) 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_sparjac (d02nj). Either or both of the integrator diagnostic function nag_ode_ivp_stiff_integ_diag (d02ny), or the sparse matrix linear algebra diagnostic function nag_ode_ivp_stiff_sparjac_diag (d02nx), may be called after the call to nag_ode_ivp_stiff_imp_sparjac (d02nj). 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_sparjac (d02nj) without restarting the integration process.
Input Parameters
Output Parameters
(1) |
(2) |
Input Parameters
Output Parameters
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: d02nj_example
function d02nj_example fprintf('d02nj example results\n\n'); % For communication with monitr. global ncall tkeep ykeep jacobian; jacobian = 'Analytic'; d02nj_subexample; jacobian = 'Full_info'; d02nj_subexample; % Plot results. fig1 = figure; display_plot(tkeep, ykeep); function d02nj_subexample global ncall tkeep ykeep jacobian; % Initialize setup variables and arrays. neq = int64(3); neqmax = neq; maxord = int64(5); sdysav = maxord+1; petzld = true; const = zeros(6, 1); tcrit = 0; hmin = 1.0e-10; hmax = 10; h0 = 0; maxstp = int64(200); mxhnil = int64(5); rwork = zeros(50+4*neq, 1); % setup routine [const, rwork, ifail] = d02nv(... neqmax, sdysav, maxord, 'Newton', petzld, ... const, tcrit, hmin, hmax, h0, maxstp, ... mxhnil, 'Average-L2', rwork); % sparse Jacobian setup. nwkjac = int64(100); ia = int64([1; 3; 6; 9]); ja = int64([1; 2; 1; 2; 3; 1; 2; 3]); njcpvt = int64(150); sens = 1.0e-6; u = 0.1; eta = 1.0e-4; lblock = true; [jacpvt, rwork, ifail] = d02nu(... neq, neqmax, jacobian, nwkjac, ia, ja, ... njcpvt, sens, u, eta, lblock, rwork); % Initialize input arguments for integrator t = 0; tout = 10.0; y = [1; 0; 0]; ydot = zeros(neq, 1); itol = int64(3); rtol = [0.0001; 0.001; 0.0001]; atol = [1e-07]; inform = zeros(23,1,'int64'); ysave = zeros(neq, sdysav); wkjac = zeros(nwkjac, 1); lderiv = [false; true]; itrace = int64(0); itask = int64(1); % Output header and initial results. fprintf('Jacobian = %s\n\n',jacobian); fprintf(' x y\n'); fprintf('%8.3f %8.5f %8.5f %8.5f\n',t,y); if (jacobian(1)=='F') % Prepare to store results for plotting. ncall = 2; ykeep = y; tkeep = [t]; end % Integrate to tout by overshooting (itask=1) using BDF with Newton, % and the Petzold error test. % The monitr routine forces a return when y(1)<= 0.9. % ifail = 12 is deliberately triggered, so turn warnings off temporarily wstat = warning(); warning('OFF'); [t, tout, y, ydot, rwork, inform, ysave, wkjac, jacpvt, lderiv, ifail] ... = d02nj(... t, tout, y, ydot, rwork, rtol, atol, itol, inform, @resid, ... ysave, @jac, wkjac, jacpvt, @monitr, lderiv, itask, itrace); warning(wstat); % Output results. fprintf('%8.3f %8.5f %8.5f %8.5f\n',t,y); % d02ny is an integrator diagnostic routine which can be called % after d02nj. [hu, h, tcur, tolsf, nst, nre, nje, nqu, nq, niter, imxer, algequ, ifail] ... = d02ny(... neq, neqmax, 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); % d02nx is a sparse linear algebra diagnostic routine which can be % called after d02nj. icall = int64(0); [liwreq, liwusd, lrwreq, lrwusd, nlu, nz, ngp, isplit, igrow, nblock]... = d02nx(... icall, lblock, inform); fprintf(' sparse jacobian statistics:\n'); fprintf(' njcpvt - required = %3d, used = %3d\n',liwreq,liwusd); fprintf(' nwkjac - required = %3d, used = %3d)\n',lrwreq,lrwusd); fprintf(' No. of LU-decomps = %3d, No. of nonzeros = %3d\n',nlu,nz); fprintf([' No. of function calls to form Jacobian = %3d, try ', ... 'isplit = %3d\n'], ngp, isplit); fprintf([' Growth estimate = %d, No. of blocks on diagonal %3d\n\n'], ... igrow, nblock); function pdj = jac(neq, t, y, ydot, h, d, j, pdj) % Evaluate the Jacobian. pdj = zeros(neq,1); hxd = h*d; if j == 1 pdj(1) = -hxd*(1.0); pdj(2) = -hxd*(0.04); elseif j == 2 pdj(1) = -hxd*(1.0); pdj(2) = -hxd*(-1.0e4*y(3)-6.0e7*y(2)) + 1; pdj(3) = -hxd*(6.0e7*y(2)); elseif j == 3 pdj(1) = -hxd*(1.0); pdj(2) = -hxd*(-1.0e4*y(2)); pdj(3) = -hxd*(0.0) + 1; end function [hnext, y, imon, inln, hmin, hmax] = ... monitr(neq, neqmax, t, hlast, hnext, y, ydot, ... ysave, r, acor, imon, hmin, hmax, nqu) global ncall tkeep ykeep jacobian; % Terminate integration when y(1) <= 0.9 if (y(1) <= 0.9) imon = int64(-2); end inln = int64(0); % Store current results for plotting later on. if (jacobian(1)=='F') tkeep(ncall,1) = t; ykeep(:,ncall) = y; ncall = ncall + 1; end function [r, ires] = resid(neq, t, y, ydot, ires) r = zeros(neq,1); r(1) = 0; r(2) = -ydot(2); r(3) = -ydot(3); if ires == 1 r(1) = y(1) + y(2) + y(3) - 1 + r(1); r(2) = 0.04*y(1) - 1.0e4*y(2)*y(3) - 3.0e7*y(2)*y(2) + r(2); r(3) = 3.0e7*y(2)*y(2) + r(3); end function display_plot(x, y) % Formatting for title and axis labels. % Plot one of the curves and then add the other two. hline1 = semilogx(x, y(1,:)); hold on [haxes, hline2, hline3] = plotyy(x, y(3,:),x, y(2,:), ... 'semilogx', 'semilogx'); % Set the axis limits and the tick specifications to beautify the plot. set(haxes(1), 'YLim', [-0.05 1.2]); set(haxes(1), 'XMinorTick', 'on', 'YMinorTick', 'on'); set(haxes(1), 'YTick', [0.0:0.2:1.2]); set(haxes(2), 'YLim', [0.0 4e-5]); set(haxes(2), 'YMinorTick', 'on'); set(haxes(2), 'YTick', [5e-6:5e-6:3.5e-5]); for iaxis = 1:2 % These properties must be the same for both sets of axes. set(haxes(iaxis), 'XLim', [0 12]); set(haxes(iaxis), 'XTick', [0.0001 0.001 0.01 0.1 1 10]); end set(gca, 'box', 'off'); % Add title. ht = title({'Stiff Robertson Problem (Implicit DAE):',... 'BDF with Newton Iterations'}); set(ht,'Position',[0.02,1.15,0.0]); % Label the x axis, and both y axes. xlabel('x'); ylabel(haxes(1),'Solution (a,c)'); ylabel(haxes(2),'Solution (b)'); % Add a legend. legend('a','c','b','Location','Best'); % Set some features of the three lines. set(hline1, 'Marker', '+','Linestyle','-','Color','red'); set(hline2, 'Marker', '*','Linestyle',':','Color','green'); set(hline3, 'Marker', 'x','Linestyle','--','Color','blue');
d02nj example results Jacobian = Analytic x y 0.000 1.00000 0.00000 0.00000 4.966 0.89195 0.00002 0.10803 Diagnostic information integration status: last and next step sizes = 0.60059, 0.60059 integration stopped at x = 4.96639 algorithm statistics: number of time-steps and Newton iterations = 52 119 number of residual and jacobian evaluations = 132 13 order of method last used and next to use = 4 4 component with largest error = 3 sparse jacobian statistics: njcpvt - required = 99, used = 150 nwkjac - required = 31, used = 75) No. of LU-decomps = 13, No. of nonzeros = 8 No. of function calls to form Jacobian = 0, try isplit = 73 Growth estimate = 1035, No. of blocks on diagonal 1 Jacobian = Full_info x y 0.000 1.00000 0.00000 0.00000 4.966 0.89195 0.00002 0.10803 Diagnostic information integration status: last and next step sizes = 0.60059, 0.60059 integration stopped at x = 4.96639 algorithm statistics: number of time-steps and Newton iterations = 52 119 number of residual and jacobian evaluations = 131 13 order of method last used and next to use = 4 4 component with largest error = 3 sparse jacobian statistics: njcpvt - required = 99, used = 150 nwkjac - required = 31, used = 75) No. of LU-decomps = 13, No. of nonzeros = 8 No. of function calls to form Jacobian = 0, try isplit = 73 Growth estimate = 1035, No. of blocks on diagonal 1