Input Parameters
Output Parameters
Input Parameters
Output Parameters
Input Parameters
Output Parameters
Input Parameters
Output Parameters
Input Parameters
Output Parameters
Input Parameters
Output Parameters
Input Parameters
Output Parameters
Open in the MATLAB editor: d02tl_example
function d02tl_example fprintf('d02tl example results\n\n'); global omega sqrofr % Initialize variables and arrays. neq = int64(3); nlbc = neq; nrbc = neq; ncol = int64(7); mmax = int64(3); m = int64([1; 3; 2]); tols = [1; 1; 1]/10^4; % Set values for problem-specific physical parameters. omega = 1; r = 10^6; % Set up the mesh. nmesh = int64(11); mxmesh = int64(51); ipmesh = zeros(mxmesh, 1, 'int64'); mesh = zeros(mxmesh, 1); mesh(1:nmesh) = [0:0.1:1]; ipmesh(1) = 1; ipmesh(2:nmesh-1) = 2; ipmesh(nmesh) = 1; % d02tv is a setup routine to be called prior to d02tl. [rcomm, icomm, ifail] = d02tv(... m, nlbc, nrbc, ncol, tols, nmesh, mesh, ipmesh); % Set number of continuation steps. ncont = 3; % We run through the calculation three times with different parameter sets. for jcont = 1:ncont sqrofr = sqrt(r); fprintf('\n Tolerance = %8.1e R = %10.3e\n\n', tols(1), r); % Call d02tk to solve BVP for this set of parameters. [rcomm, icomm, ifail] = ... d02tl(... @ffun, @fjac, @gafun, @gbfun, @gajac, @gbjac, @guess, rcomm, icomm); % Call d02tz to extract mesh from solution. [nmesh, mesh, ipmesh, ermx, iermx, ijermx, ifail] = ... d02tz( ... mxmesh, rcomm, icomm); % Output mesh results. fprintf(' Mesh size = %d\n', nmesh); fprintf(' Maximum error = %10.2e in interval %d for component %d\n\n', ... ermx, iermx, ijermx); fprintf('Mesh points:\n'); for imesh = 1:nmesh fprintf( '%4d(%d) %6.4f', imesh, ipmesh(imesh), mesh(imesh)); if mod(imesh, 4) == 0 fprintf('\n'); end end % Output solution, and store it for plotting. xarray = zeros(nmesh, 1); yarray = zeros(nmesh, 3); fprintf('\n\n x f f'' g\n'); for imesh = 1:nmesh % Call d02ty to perform interpolation on the solution. [y, rcomm, ifail] = d02ty(... mesh(imesh), neq, mmax, rcomm, icomm); fprintf(' %6.3f %8.4f %8.4f %8.4f\n', mesh(imesh), y(:,1)); xarray(imesh) = mesh(imesh); yarray(imesh, 1:3) = y(1:3,1); end % Plot results for this parameter set. if jcont==1 fig1 = figure; else if jcont==2 fig2 = figure; else fig3 = figure; end end display_plot(xarray, yarray, r); % Select mesh for next calculation. if jcont < ncont r = 100*r; ipmesh(2:nmesh-1) = 2; % d02tx allows the current solution to be used for continuation [rcomm, icomm, ifail] = d02tx(... nmesh, mesh, ipmesh, rcomm, icomm); end end function [f, user] = ffun(x, y, neq, m, user) % Evaluate derivative functions (rhs of system of ODEs). global omega sqrofr; % For communication with main routine. f = zeros(neq, 1); f(1,1) = y(2,1); f(2,1) = -(y(1,1)*y(2,3) + y(3,1)*y(3,2))*sqrofr; f(3,1) = (y(2,1)*y(3,1) - y(1,1)*y(3,2))*sqrofr; function [dfdy, user] = fjac(x, y, neq, m, dfdy, user) % Evaluate Jacobians (partial derivatives of f). global omega sqrofr dfdy = zeros(neq, neq, 3); dfdy(1,2,1) = 1.0; dfdy(2,1,1) = -y(2,3)*sqrofr; dfdy(2,2,3) = -y(1,1)*sqrofr; dfdy(2,3,1) = -y(3,2)*sqrofr; dfdy(2,3,2) = -y(3,1)*sqrofr; dfdy(3,1,1) = -y(3,2)*sqrofr; dfdy(3,2,1) = y(3,1)*sqrofr; dfdy(3,3,1) = y(2,1)*sqrofr; dfdy(3,3,2) = -y(1,1)*sqrofr; function [ga, user] = gafun(ya, neq, m, nlbc, user) % Evaluate boundary conditions at left-hand end of range. global omega sqrofr ga = zeros(nlbc, 1); ga(1) = ya(1); ga(2) = ya(2); ga(3) = ya(3) - omega; function [dgady, user] = gajac(ya, neq, m, nlbc, dgady, user) % Evaluate Jacobians (partial derivatives of ga). dgady = zeros(nlbc, neq, 3); dgady(1,1,1) = 1; dgady(2,2,1) = 1; dgady(3,3,1) = 1; function [gb, user] = gbfun(yb, neq, m, nrbc, user) % Evaluate boundary conditions at right-hand end of range. global omega sqrofr gb = zeros(nrbc, 1); gb(1) = yb(1); gb(2) = yb(2); gb(3) = yb(3) + omega; function [dgbdy, user] = gbjac(yb, neq, m, nrbc, dgbdy, user) % Evaluate Jacobians (partial derivatives of gb). dgbdy = zeros(nrbc, neq, 3); dgbdy(1,1,1) = 1; dgbdy(2,2,1) = 1; dgbdy(3,3,1) = 1; function [y, dym, user] = guess(x, neq, m, user) % Evaluate initial approximations to solution components and derivatives. global omega sqrofr y = zeros(neq, 3); dym = zeros(neq, 1); y(1,1) = -x^2*(x - 0.5)*(x - 1)^2; y(2,1) = -x*(x - 1)*(5*x^2 - 5*x + 1); y(3,1) = -8*omega*(x - 0.5)^3; y(2,2) = -(20*x^3 - 30*x^2 + 12*x - 1); y(2,3) = -(60*x^2 - 60*x + 12*x); y(3,2) = -24*omega*(x - 0.5)^2; dym(1) = y(2,1); dym(2) = -(120*x - 60); dym(3) = -56*omega*(x - 0.5); function display_plot(x, y, r) % Plot two of the curves, then add the other one. [haxes, hline1, hline2] = plotyy(x, y(:,2), x, y(:,3)); % We want the third curve to be plotted on the left-hand y-axis. hold(haxes(1), 'on'); hline3 = plot(x, y(:,1)); % Set the axis limits and the tick specifications to beautify the plot. set(haxes(1), 'YLim', [-0.1 0.4]); set(haxes(2), 'YLim', [-1 1]); set(haxes(1), 'XMinorTick', 'on', 'YMinorTick', 'on'); set(haxes(2), 'YMinorTick', 'on'); set(haxes(1), 'YTick', [-0.1:0.1:0.4]); set(haxes(2), 'YTick', [-1:0.5:1]); for iaxis = 1:2 % These properties must be the same for both sets of axes. set(haxes(iaxis), 'XLim', [0 1]); set(haxes(iaxis), 'XTick', [0:0.2:1]); end set(gca, 'box', 'off'); % Add title. ord = log10(r); title(['Flow between Discs, Re = 10^n, n = ', num2str(ord)]); % Label the axes. xlabel('x'); ylabel(haxes(1), 'f and f'''); ylabel(haxes(2), 'g'); % Add a legend. legend('f''','f','g','Location','Best') % Set some features of the three lines. set(hline1, 'Linewidth', 0.25, 'Marker', '+', 'LineStyle', '-', ... 'Color', 'Magenta'); set(hline2, 'Linewidth', 0.25, 'Marker', 'x', 'LineStyle', '--'); set(hline3, 'Linewidth', 0.25, 'Marker', '*', 'LineStyle', ':');
d02tl example results Tolerance = 1.0e-04 R = 1.000e+06 Mesh size = 21 Maximum error = 6.16e-10 in interval 20 for component 3 Mesh points: 1(1) 0.0000 2(3) 0.0500 3(2) 0.1000 4(3) 0.1500 5(2) 0.2000 6(3) 0.2500 7(2) 0.3000 8(3) 0.3500 9(2) 0.4000 10(3) 0.4500 11(2) 0.5000 12(3) 0.5500 13(2) 0.6000 14(3) 0.6500 15(2) 0.7000 16(3) 0.7500 17(2) 0.8000 18(3) 0.8500 19(2) 0.9000 20(3) 0.9500 21(1) 1.0000 x f f' g 0.000 0.0000 0.0000 1.0000 0.050 0.0070 0.1805 0.4416 0.100 0.0141 0.0977 0.1886 0.150 0.0171 0.0252 0.0952 0.200 0.0172 -0.0165 0.0595 0.250 0.0157 -0.0400 0.0427 0.300 0.0133 -0.0540 0.0322 0.350 0.0104 -0.0628 0.0236 0.400 0.0071 -0.0683 0.0156 0.450 0.0036 -0.0714 0.0078 0.500 0.0000 -0.0724 0.0000 0.550 -0.0036 -0.0714 -0.0078 0.600 -0.0071 -0.0683 -0.0156 0.650 -0.0104 -0.0628 -0.0236 0.700 -0.0133 -0.0540 -0.0322 0.750 -0.0157 -0.0400 -0.0427 0.800 -0.0172 -0.0165 -0.0595 0.850 -0.0171 0.0252 -0.0952 0.900 -0.0141 0.0977 -0.1886 0.950 -0.0070 0.1805 -0.4416 1.000 -0.0000 -0.0000 -1.0000 Tolerance = 1.0e-04 R = 1.000e+08 Mesh size = 21 Maximum error = 4.49e-09 in interval 6 for component 3 Mesh points: 1(1) 0.0000 2(3) 0.0176 3(2) 0.0351 4(3) 0.0520 5(2) 0.0689 6(3) 0.0859 7(2) 0.1030 8(3) 0.1351 9(2) 0.1672 10(3) 0.2306 11(2) 0.2939 12(3) 0.4713 13(2) 0.6486 14(3) 0.7455 15(2) 0.8423 16(3) 0.8824 17(2) 0.9225 18(3) 0.9449 19(2) 0.9673 20(3) 0.9836 21(1) 1.0000 x f f' g 0.000 0.0000 0.0000 1.0000 0.018 0.0025 0.1713 0.3923 0.035 0.0047 0.0824 0.1381 0.052 0.0056 0.0267 0.0521 0.069 0.0058 0.0025 0.0213 0.086 0.0057 -0.0073 0.0097 0.103 0.0056 -0.0113 0.0053 0.135 0.0052 -0.0135 0.0027 0.167 0.0047 -0.0140 0.0020 0.231 0.0038 -0.0142 0.0015 0.294 0.0029 -0.0142 0.0012 0.471 0.0004 -0.0143 0.0002 0.649 -0.0021 -0.0143 -0.0008 0.745 -0.0035 -0.0142 -0.0014 0.842 -0.0049 -0.0139 -0.0022 0.882 -0.0054 -0.0127 -0.0036 0.922 -0.0058 -0.0036 -0.0141 0.945 -0.0057 0.0205 -0.0439 0.967 -0.0045 0.0937 -0.1592 0.984 -0.0023 0.1753 -0.4208 1.000 -0.0000 0.0000 -1.0000 Tolerance = 1.0e-04 R = 1.000e+10 Mesh size = 21 Maximum error = 3.13e-06 in interval 7 for component 3 Mesh points: 1(1) 0.0000 2(3) 0.0063 3(2) 0.0125 4(3) 0.0185 5(2) 0.0245 6(3) 0.0308 7(2) 0.0370 8(3) 0.0500 9(2) 0.0629 10(3) 0.0942 11(2) 0.1256 12(3) 0.4190 13(2) 0.7125 14(3) 0.8246 15(2) 0.9368 16(3) 0.9544 17(2) 0.9719 18(3) 0.9803 19(2) 0.9886 20(3) 0.9943 21(1) 1.0000 x f f' g 0.000 0.0000 0.0000 1.0000 0.006 0.0009 0.1623 0.3422 0.013 0.0016 0.0665 0.1021 0.019 0.0018 0.0204 0.0318 0.025 0.0019 0.0041 0.0099 0.031 0.0019 -0.0014 0.0028 0.037 0.0019 -0.0031 0.0007 0.050 0.0019 -0.0038 -0.0002 0.063 0.0018 -0.0038 -0.0003 0.094 0.0017 -0.0039 -0.0003 0.126 0.0016 -0.0039 -0.0002 0.419 0.0004 -0.0041 -0.0001 0.712 -0.0008 -0.0042 0.0001 0.825 -0.0013 -0.0043 0.0002 0.937 -0.0018 -0.0043 0.0003 0.954 -0.0019 -0.0042 0.0001 0.972 -0.0019 -0.0003 -0.0049 0.980 -0.0019 0.0152 -0.0252 0.989 -0.0015 0.0809 -0.1279 0.994 -0.0008 0.1699 -0.3814 1.000 0.0000 0.0000 -1.0000