None.
Open in the MATLAB editor: d02pr_example
function d02pr_example fprintf('d02pr example results\n\n'); % Set initial conditions and input method = int64(-3); tstart = 0; tend = 6*pi; ecc = 0.7; yinit = [1-ecc; 0; 0; sqrt((1+ecc)/(1-ecc))]; hstart = 0; thresh = [1e-10; 1e-10; 1e-10; 1e-10]; n = int64(4); npts = 96; tol0 = 1.0E-4; ysave = zeros(npts+1, n); tsave = zeros(npts+1, 1); % Set control for output tol = 10.0*tol0; tinc = (tend-tstart)/npts; % We run through the calculation twice with two tolerance values for i = 1:2 tol = tol*0.1; tendnu = tstart + tinc; % Call setup function [iwsav, rwsav, ifail] = d02pq(tstart, tendnu, yinit, tol, thresh, method); fprintf('\nCalculation with TOL = %8.1e\n\n', tol); fprintf(' t y1 y2 y3 y4\n'); fprintf(' %6.3f %7.3f %7.3f %7.3f %7.3f\n', tstart, yinit); tsave(1) = tstart; ysave(1, :) = yinit; tnow = tstart; j=1; while tnow < tend [tnow, ynow, ypnow, user, iwsav, rwsav, ifail] = ... d02pf(@f, n, iwsav, rwsav); if tnow >= tendnu % Just print some of the results if rem(j, 16) == 0 fprintf(' %6.3f %7.3f %7.3f %7.3f %7.3f\n', tnow, ynow); end j = j+1; tsave(j) = tnow; ysave(j, :) = ynow; if tnow < tend tendnu = tendnu + tinc; [iwsav, rwsav, ifail] = d02pr(tendnu, iwsav, rwsav); end end end [fevals, stepcost, waste, stepsok, hnext, iwsav, ifail] = d02pt(iwsav, rwsav); fprintf('Cost of the integration in evaluations of f is %d\n', fevals); end % Plot results fig1 = figure; hold on; xlabel('Orbit - x'); ylabel('Orbit - y'); plot(ysave(:,1), ysave(:, 2), '-xr'); % Plot errors with a different scale ax1 = gca; ax2 = axes('Position',get(ax1,'Position'),... 'XAxisLocation','top',... 'YAxisLocation','right',... 'Color','none',... 'XColor','k','YColor','k'); hold on; axis([-0.25 0.05 -0.1 0.1]); xlabel('x Deviation from True Ellipse'); ylabel('y Deviation from True Ellipse'); d = dev(ysave(:,1), ysave(:, 2)); plot(ax2, d.*cos(tsave), d.*sin(tsave),'-*b'); text(-0.05, 0, 'Deviation', 'Color', 'b'); function [yp, user] = f(t, n, y, user) r = sqrt(y(1)^2+y(2)^2); yp = [y(3); y(4); -y(1)/r^3; -y(2)/r^3]; function [d] = dev(x, y) ecc = 0.7; d = abs((x+ecc).*(x+ecc)+y.*y/(ecc*ecc)-1);
d02pr example results Calculation with TOL = 1.0e-04 t y1 y2 y3 y4 0.000 0.300 0.000 0.000 2.380 3.142 -1.700 0.000 -0.000 -0.420 6.283 0.300 -0.000 0.000 2.380 9.425 -1.700 0.000 -0.000 -0.420 12.566 0.300 -0.000 0.000 2.380 15.708 -1.700 0.000 -0.000 -0.420 18.850 0.300 -0.000 0.001 2.380 Cost of the integration in evaluations of f is 1443 Calculation with TOL = 1.0e-05 t y1 y2 y3 y4 0.000 0.300 0.000 0.000 2.380 3.142 -1.700 0.000 -0.000 -0.420 6.283 0.300 -0.000 0.000 2.380 9.425 -1.700 0.000 -0.000 -0.420 12.566 0.300 -0.000 0.000 2.380 15.708 -1.700 0.000 -0.000 -0.420 18.850 0.300 -0.000 0.000 2.380 Cost of the integration in evaluations of f is 1509