(1) |
Open in the MATLAB editor: e02dh_example
function e02dh_example fprintf('e02dh example results\n\n'); mx = 11; my = 9; start = 'C'; x = [0:0.5:5]; y = [0:0.5:4]; % f = (x+1)*cosy + noise f = [ 1.0000, 0.88758, 0.54030, 0.070737,-0.41515, ... -0.80114,-0.97999,-0.93446, -0.65664, ... 1.5000, 1.3564, 0.82045, 0.10611, -0.62422, ... -1.2317, -1.4850, -1.3047, -0.98547, ... 2.0600, 1.7552, 1.0806, 0.15147, -0.83229, ... -1.6023, -1.9700, -1.8729, -1.4073, ... 2.5700, 2.1240, 1.3508, 0.17684, -1.0404, ... -2.0029, -2.4750, -2.3511, -1.6741, ... 3.0000, 2.6427, 1.6309, 0.21221, -1.2484, ... -2.2034, -2.9700, -2.8094, -1.9809, ... 3.5000, 3.1715, 1.8611, 0.24458, -1.4565, ... -2.8640, -3.2650, -3.2776, -2.2878, ... 4.0400, 3.5103, 2.0612, 0.28595, -1.6946, ... -3.2046, -3.9600, -3.7958, -2.6146, ... 4.5000, 3.9391, 2.4314, 0.31632, -1.8627, ... -3.6351, -4.4550, -4.2141, -2.9314, ... 5.0400, 4.3879, 2.7515, 0.35369, -2.0707, ... -4.0057, -4.9700, -4.6823, -3.2382, ... 5.5050, 4.8367, 2.9717, 0.38505, -2.2888, ... -4.4033, -5.4450, -5.1405, -3.5950, ... 6.0000, 5.2755, 3.2418, 0.42442, -2.4769, ... -4.8169, -5.9300, -5.6387, -3.9319]; s = 0.1; ngx = 6; xlo = 0; xhi = 5; ngy = 5; ylo = 0; yhi = 4; nxest = mx + 4; nyest = my + 4; lamda = zeros(nxest, 1); mu = zeros(nyest, 1); wrk = zeros(4*(mx+my) + 11*(nxest+nyest) + nxest*my + max(my,nxest) + 54, 1); iwrk = zeros(3 + mx + my + nxest + nyest, 1, 'int64'); % Determine the spline approximation [nx, lamda, ny, mu, c, fp, wrk, iwrk, ifail] = ... e02dc( ... start, x, y, f, s, int64(0), lamda, int64(0), mu, wrk, iwrk); fprintf('\nSpline fit used smoothing factor S = %13.4e.\n', s); fprintf('Number of knots in each direction = %d, %d\n', nx, ny); fprintf('\nSum of squared residuals = %13.4e.\n', fp); % Evaluate the spline derivative on a different rectangular grid with % ngx*ngy points over the domain (xlo to xhi) x (ylo to yhi). gridx = [xlo:(xhi-xlo)/(ngx-1):xhi]; gridy = [ylo:(yhi-ylo)/(ngy-1):yhi]; % Evaluate spline (nux=nuy=0) nux = int64(0); nuy = int64(0); [z, ifail] = e02dh( ... gridx, gridy, lamda(1:nx), mu(1:ny), c, nux, nuy); nux = int64(1); % Evaluate spline partial derivative of order (nux, nuy) [zder, ifail] = e02dh( ... gridx, gridy, lamda(1:nx), mu(1:ny), c, nux, nuy); % Spline partial derivatives to evaluate have order nux,nuy. fprintf('\nDerivative of spline has order nux, nuy = %d, %d.\n\n', nux, nuy); % Print the spline evaluations rlabs = cell(size(gridy)); for i = 1:ngy rlabs{i} = num2str(gridy(i)); end clabs = cell(size(gridx)); for i = 1:ngx clabs{i} = num2str(gridx(i)); end title = 'Spline evaluated on X-Y grid (X across, Y down):'; [ifail] = x04cb('G', 'N', reshape(z, ngy, ngx), 'F8.3', title, ... 'C', rlabs, 'C', clabs, int64(80), int64(0)); fprintf('\n'); title = 'Spline derivative evaluated on X-Y grid:'; [ifail] = x04cb('G', 'N', reshape(zder, ngy, ngx), 'F8.3', title, ... 'C', rlabs, 'C', clabs, int64(80), int64(0));
e02dh example results Spline fit used smoothing factor S = 1.0000e-01. Number of knots in each direction = 10, 13 Sum of squared residuals = 1.0004e-01. Derivative of spline has order nux, nuy = 1, 0. Spline evaluated on X-Y grid (X across, Y down): 0 1 2 3 4 5 0 0.992 2.043 3.029 4.014 5.021 5.997 1 0.541 1.088 1.607 2.142 2.705 3.239 2 -0.417 -0.829 -1.241 -1.665 -2.083 -2.485 3 -0.978 -1.975 -2.914 -3.913 -4.965 -5.924 4 -0.648 -1.363 -1.991 -2.606 -3.251 -3.933 Spline derivative evaluated on X-Y grid: 0 1 2 3 4 5 0 1.093 1.013 0.970 1.004 1.001 0.939 1 0.565 0.531 0.515 0.558 0.559 0.499 2 -0.429 -0.404 -0.421 -0.423 -0.412 -0.389 3 -1.060 -0.951 -0.949 -1.048 -1.031 -0.861 4 -0.779 -0.661 -0.608 -0.628 -0.663 -0.701