Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.
On entry, | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | . |
Open in the MATLAB editor: d02xj_example
function d02xj_example fprintf('d02xj example results\n\n'); % 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 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
d02xj 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