Input Parameters
Output Parameters
Input Parameters
Output Parameters
Input Parameters
Output Parameters
Input Parameters
Output Parameters
Input Parameters
Output Parameters
Input Parameters
Output Parameters
None.
Open in the MATLAB editor: d02tk_example
function d02tk_example fprintf('d02tk example results\n\n'); global omega sqrofr; % For communication with local functions % Initialize variables and arrays. neq = 3; nlbc = 3; nrbc = 3; ncol = 7; mmax = 3; m = [1; 3; 2]; tols = [1.0e-04; 1.0e-04; 1.0e-04]; % Set values for problem-specific physical parameters. omega = 1.0; r = 1.0e+6; % Set up the mesh. nmesh = 11; mxmesh = 51; ipmesh = zeros(mxmesh, 1); mesh = zeros(mxmesh, 1); % Set location of mesh boundaries, then calculate initial spacing. mesh(1) = 0.0; mesh(nmesh) = 1.0; mstep = (mesh(nmesh) - mesh(1))/double(nmesh-1); for i = 2:nmesh-1 mesh(i) = mstep*double(i-1); ipmesh(i) = 2; end % Specify mesh end points as fixed. ipmesh(1) = 1; ipmesh(nmesh) = 1; % d02tv is a setup routine to be called prior to d02tk. [work, iwork, ifail] = d02tv( ... int64(m), int64(nlbc), int64(nrbc), ... int64(ncol), tols, int64(nmesh), mesh, ... int64(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. [work, iwork, ifail] = d02tk( ... @ffun, @fjac, @gafun, @gbfun, @gajac, ... @gbjac, @guess, work, iwork); % Call d02tz to extract mesh from solution. [nmesh, mesh, ipmesh, ermx, iermx, ijermx, ifail] = ... d02tz( ... int64(mxmesh), work, iwork); % Output mesh results. fprintf(' Used a mesh of %d points\n', nmesh); fprintf([' Maximum error = %10.2e in interval %d for component %d\n\n', ... ' Mesh points:\n'], ermx, iermx, ijermx); 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, work, ifail] = d02ty( ... mesh(imesh), int64(neq), int64(mmax), ... work, iwork); fprintf(' %6.3f %8.4f %8.4f %8.4f\n', mesh(imesh), ... y(1,1), y(2,1), y(3,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; elseif jcont==2 fig2 = figure; else fig3 = figure; end display_plot(xarray, yarray, r) % Select mesh for next calculation. if jcont < ncont r = r*1.0e+02; for i = 2:nmesh-1 ipmesh(i) = 2; end % d02tx allows the current solution to be used as an initial % approximation to the solution of a related problem. [work, iwork, ifail] = d02tx( ... nmesh, mesh, ipmesh, work, iwork); end end function [f] = ffun(x, y, neq, m) % 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] = fjac(x, y, neq, m) % Evaluate Jacobians (partial derivatives of f). global omega sqrofr; % For communication with main routine. 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] = gafun(ya, neq, m, nlbc) % Evaluate boundary conditions at left-hand end of range. global omega sqrofr; % For communication with main routine. ga = zeros(nlbc, 1); ga(1) = ya(1); ga(2) = ya(2); ga(3) = ya(3) - omega; function [dgady] = gajac(ya, neq, m, nlbc) % Evaluate Jacobians (partial derivatives of ga). dgady = zeros(nlbc, neq, 3); dgady(1,1,1) = 1.0; dgady(2,2,1) = 1.0; dgady(3,3,1) = 1.0; function [gb] = gbfun(yb, neq, m, nrbc) % Evaluate boundary conditions at right-hand end of range. global omega sqrofr; % For communication with main routine. gb = zeros(nrbc, 1); gb(1) = yb(1); gb(2) = yb(2); gb(3) = yb(3) + omega; function [dgbdy] = gbjac(yb, neq, m, nrbc) % Evaluate Jacobians (partial derivatives of gb). dgbdy = zeros(nrbc, neq, 3); dgbdy(1,1,1) = 1.0; dgbdy(2,2,1) = 1.0; dgbdy(3,3,1) = 1.0; function [y, dym] = guess(x, neq, m) % Evaluate initial approximations to solution components and derivatives. global omega sqrofr; % For communication with main routine. y = zeros(neq, 3); dym = zeros(neq, 1); y(1,1) = -x^2*(x - 0.5)*(x - 1.0)^2; y(2,1) = -x*(x - 1.0)*(5.0*x^2 - 5.0*x + 1.0); y(3,1) = -8.0*omega*(x - 0.5)^3; y(2,2) = -(20.0*x^3 - 30.0*x^2 + 12.0*x - 1.0); y(2,3) = -(60.0*x^2 - 60.0*x + 12.0*x); y(3,2) = -24.0*omega*(x - 0.5)^2; dym(1) = y(2,1); dym(2) = -(120.0*x - 60.0); dym(3) = -56.0*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(1), 'XMinorTick', 'on', 'YMinorTick', 'on'); set(haxes(1), 'YTick', [-0.1:0.1:0.4]); set(haxes(2), 'YLim', [-1 1]); set(haxes(2), 'YMinorTick', 'on'); 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'); % no ticks on opposite axes. % Add title. ord = log10(r); title({'Incompressible Fluid Flow between Discs.', ... ['Solutions for 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', ':');
d02tk example results Tolerance = 1.0e-04 R = 1.000e+06 Used a mesh of 21 points 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 Used a mesh of 21 points 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 Used a mesh of 21 points 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