At Mark 22: | neq was made optional |
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 | , |
or | the BDF integrator was not previously used, |
or | the Petzold error test, if applicable, was used. |
Open in the MATLAB editor: d02xk_example
function d02xk_example fprintf('d02xk example results\n\n'); % Initialize setup 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); % BDF with Newton iterations. [const, rwork, ifail] = d02nv( ... neqmax, sdysav, maxord, 'Newton', petzld, ... const, tcrit, hmin, hmax, h0, maxstp, ... mxhnil, 'Average-L2', rwork); % Numerical Jacobian nwkjac = neqmax*(neqmax + 1); [rwork, ifail] = d02ns( ... neq, neqmax, 'Numerical', nwkjac, rwork); % Initialize variables and arrays. njcpvt = int64(1); wkjac = zeros(nwkjac, 1); ydot = zeros(neq, 1); ysave = zeros(neq, sdysav); inform(1:23) = int64(0); jacpvt(1) = int64(0); algequ = zeros(neq, 1); % Integrate to tout by overshooting (itask = 1). % At monitoring stages output intermediate solutions after interpolating. t = 0; tout = 10.0; itask = int64(1); iout = 1; xout = 2; y = [1; 0; 0]; itol = int64(1); rtol = [1e-04]; atol = [1e-07]; % Output header and initial results. fprintf('\n x y(1) y(2) y(3)\n'); fprintf(' %8.3f %12.4f %12.2e %11.4f\n', t, y); % bogus initial entry values for unitialized input parameters. irevcm = int64(-999); imon = irevcm; inln = irevcm; ires = irevcm; % Ask for warning messages only. itrace = int64(0); % The reverse communication process is controlled by the value of irevcm % (which is 0 for the final exit). while (irevcm ~= 0) [t, y, ydot, rwork, inform, ysave, wkjac, jacpvt, imon, inln, ires, ... irevcm, ifail] = d02nm( ... t, tout, y, ydot, rwork, rtol, atol, itol, ... inform, ysave, wkjac, jacpvt, imon, inln, ... ires, irevcm, itask, itrace, 'neq', neq, ... 'sdysav', sdysav, 'nwkjac', nwkjac); % Evaluate the derivative, then use irevcm to place it. f(1) = -0.04*y(1) + 1.0e4*y(2)*y(3); f(2) = 0.04*y(1) - 1.0e4*y(2)*y(3) - 3.0e7*y(2)*y(2); f(3) = 3.0e7*y(2)*y(2); if (irevcm == 1 || irevcm == 3 ) lrw = 50+2*neq; rwork(lrw+1:lrw+neq) = f; elseif (irevcm == 4) lrw = 50+neq; rwork(lrw+1:lrw+neq) = f; elseif (irevcm == 5) ydot = f; elseif (irevcm == 9 && imon == 1) % Extract useful information about the current step. tc = rwork(19); hlast = rwork(15); hnext = rwork(16); nqu = int64(rwork(10)); % xout is intermediate output point. while (xout <= tc) lrw = 50+neq; [sol, ifail] = d02xk( ... xout, neq, ysave, rwork(lrw+1:lrw+neq), ... tc, nqu, hlast, hnext); % Output interpolated result, and save it for plotting. fprintf(' %8.3f %12.4f %12.2e %11.4f\n', xout, sol); iout = iout + 1; xout = iout*2; end end end
d02xk example results x y(1) y(2) y(3) 0.000 1.0000 0.00e+00 0.0000 2.000 0.9416 2.70e-05 0.0584 4.000 0.9055 2.24e-05 0.0945 6.000 0.8793 1.96e-05 0.1207 8.000 0.8585 1.77e-05 0.1414 10.000 0.8414 1.62e-05 0.1586