At Mark 22: | nwkjac was removed from the interface; neq was made optional |
. . . [...] = d02nv(...); [...] = d02ns(...); [..., ifail] = d02ng(...); if (ifail ~= 1 and ifail < 14) [...] = d02ny(...); end . . .The linear algebra setup function nag_ode_ivp_stiff_fulljac_setup (d02ns) 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_fulljac (d02ng). The integrator diagnostic function nag_ode_ivp_stiff_integ_diag (d02ny) may be called after the call to nag_ode_ivp_stiff_imp_fulljac (d02ng). 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_fulljac (d02ng) 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: d02ng_example
function d02ng_example fprintf('d02ng example results\n\n'); % switch for diagnostics output istat = 1; % Initialize setup variables and arrays. neq = int64(3); neqmax = neq; 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); % d02nv is a setup routine to be called prior to d02ng. [const, rwork, ifail] = ... d02nv( ... neqmax, sdysav, maxord, 'Functional', petzld, ... const, tcrit, hmin, hmax, h0, maxstp, mxhnil, 'Average-L2', rwork); nwkjac = int64(neq*(neq+1)); % Numerical Jacobian. [rwork, ifail] = d02ns( ... neq, neqmax, 'Numerical', nwkjac, rwork); % Initialize integration variables and arrays sol = zeros(neq, 1); wkjac = zeros(nwkjac, 1); ysave = zeros(neq, sdysav); ydot = zeros(neq, 1); inform(1:23) = int64(0); algequ = false(neq, 1); % Integrate to tout by overshooting tout in one step mode (itask=2); % use BDF with functional iteration; use vector tolerances (itol=4); % dummy d02nbz and d02nby are used for Jacobian and monitor functions. t = 0; tout = 0.1; itask = int64(2); itrace = int64(0); y = [1; 0; 0]; lderiv = [false; false]; itol = int64(4); rtol = [0.0001; 0.001; 0.0001]; atol = [1e-07; 1e-08; 1e-07]; % Output header and initial results. fprintf(' x y_1 y_2 y_3\n'); fprintf('%8.3f %8.4f %8.6f %8.4f\n',t,y); % Prepare to store results for plotting. ncall = 1; tkeep = t; ykeep = y; tstep = 0.02; % xout is intermediate output points for printing solution. iout = 1; xout = iout*tstep; while t < tout % Calculate solution at this point. [t, tout, y, ydot, rwork, inform, ysave, wkjac, lderiv, ifail] = ... d02ng( ... t, tout, y, ydot, rwork, rtol, atol, itol, inform, @resid, ... ysave, 'd02ngz', wkjac, 'd02nby', lderiv, itask, itrace); if (t<tstep) ncall = ncall+1; ykeep(:,ncall) = y; tkeep(ncall) = t; elseif (xout <= t) % Passed over intermediate output point (xout) % Interpolate the solution to get its value at xout. [hu, h, tcur, tolsf, nst, nre, nje, nqu, nq, niter, imxer, algequ, ... ifail] = d02ny( ... neq, neqmax, rwork, inform); [sol, ifail] = d02xj( ... xout, neq, ysave, neq, tcur, ... nqu, hu, h, 'sdysav', sdysav); % Accumulate results for plotting. ncall = ncall + 1; ykeep(:,ncall) = sol; tkeep(ncall) = xout; % output intermediate results fprintf('%8.3f %8.4f %8.6f %8.4f\n',xout,sol); % Bump the counter for the next output point. iout = iout + 1; xout = iout*tstep; end end % Output some statistics, if required. if istat == 1 [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); end % Plot results. fig1 = figure; display_plot(tkeep, ykeep) function [r, ires] = resid(neq, t, y, ydot, ires) % Evaluate the residual. r(1:3) = -ydot(1:3); if ires == 1 r(1) = -0.04*y(1) + 1.0e4*y(2)*y(3) + 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. hline3 = plot(x, y(3,:)); hold on; [haxes, hline1, hline2] = plotyy(x, 100*y(2,:), x, y(1,:)); % Set the axis limits and the tick specifications to beautify the plot. set(haxes(1), 'YLim', [0.0 0.0045]); set(haxes(1), 'XMinorTick', 'on', 'YMinorTick', 'on'); set(haxes(1), 'YTick', [0:0.001:0.004]); set(haxes(2), 'YLim', [0.995 1.006]); set(haxes(2), 'YMinorTick', 'on'); set(haxes(2), 'YTick', [0.995:0.002:1.005]); set(haxes(1), 'XLim', [-0.005 0.1]); set(haxes(2), 'XLim', [-0.005 0.1]); set(gca, 'box', 'off'); % no ticks on opposite axes. % Add title. ht = title({'Stiff Robertson Problem:','BDF and Functional Iteration'}); set(ht,'Position',[0.05,0.004,0.0]); % Label the x axis, and both y axes. xlabel('x'); ylabel(haxes(1), 'Solution (100*b,c)'); ylabel(haxes(2), 'Solution (a)'); % Add a legend. legend('c', '100*b', 'a', 'Location', 'Best'); % Set some features of the three lines set(hline1,'Linewidth',0.5,'Marker','+','LineStyle','-','Color','red'); set(hline2,'Linewidth',0.5,'Marker','*','LineStyle',':','Color','blue'); set(hline3,'Linewidth',0.5,'Marker','x','LineStyle','--','Color','green'); hold off;
d02ng example results x y_1 y_2 y_3 0.000 1.0000 0.000000 0.0000 0.020 0.9992 0.000036 0.0008 0.040 0.9984 0.000036 0.0016 0.060 0.9976 0.000036 0.0023 0.080 0.9969 0.000036 0.0031 0.100 0.9961 0.000036 0.0039 Diagnostic information integration status: last and next step sizes = 0.00027, 0.00053 integration stopped at x = 0.10016 algorithm statistics: number of time-steps and Newton iterations = 244 0 number of residual and jacobian evaluations = 809 0 order of method last used and next to use = 1 1 component with largest error = 2