At Mark 24: | w and iw were removed from the interface; user was added to the interface |
Input Parameters
Output Parameters
Input Parameters
Output Parameters
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 | , if , |
or | , if . |
Open in the MATLAB editor: e04yb_example
function e04yb_example fprintf('e04yb example results\n\n'); n = 3; x = [0.19; -1.34; 0.88]; m = int64(15); y = [0.14, 0.18, 0.22, 0.25, 0.29, 0.32, 0.35, 0.39, 0.37, ... 0.58, 0.73, 0.96, 1.34, 2.10, 4.39]; t = [1.0, 15.0, 1.0; 2.0, 14.0, 2.0; 3.0, 13.0, 3.0; 4.0, 12.0, 4.0; 5.0, 11.0, 5.0; 6.0, 10.0, 6.0; 7.0, 9.0, 7.0; 8.0, 8.0, 8.0; 9.0, 7.0, 7.0; 10.0, 6.0, 6.0; 11.0, 5.0, 5.0; 12.0, 4.0, 4.0; 13.0, 3.0, 3.0; 14.0, 2.0, 2.0; 15.0, 1.0, 1.0]; lb = int64(6); user = {y; t}; [fvec, fjac, b, user, ifail] = ... e04yb( ... m, @lsqfun, @lsqhes, x, lb, 'user', user); fprintf('The test point is:\n'); fprintf('%9.5f',x); fprintf('\n\n1st derivatives are consistent with residual values\n\n'); fprintf('At the test point, lsqfun gives:\n\n'); fprintf(' Residuals 1st derivatives\n'); fprintf('%10.4f %10.4f%10.4f%10.4f\n',[fvec fjac]'); fprintf('\nand lsqhes gives the lower triangle of the matrix B\n\n'); k = 1; for i = 1:n fprintf('%15.3e',b(k:(k+i-1))); fprintf('\n'); k = k + i; end function [iflag, fvecc, fjacc, user] = lsqfun(iflag, m, n, xc, ljc, user) y = user{1}; t = user{2}; fvecc = zeros(m, 1); fjacc = zeros(ljc, n); for i = 1:double(m) denom = xc(2)*t(i,2) + xc(3)*t(i,3); fvecc(i) = xc(1) + t(i,1)/denom - y(i); if (iflag ~= 0) fjacc(i,1) = 1; dummy = -1/(denom*denom); fjacc(i,2) = t(i,1)*t(i,2)*dummy; fjacc(i,3) = t(i,1)*t(i,3)*dummy; end end function [iflag, b, user] = lsqhes(iflag, m, n, fvecc, xc, lb, user) t = user{2}; b = zeros(lb, 1); sum22 = 0; sum32 = 0; sum33 = 0; for i = 1:double(m) dummy = 2*t(i,1)/(xc(2)*t(i,2)+xc(3)*t(i,3))^3; sum22 = sum22 + fvecc(i)*dummy*t(i,2)^2; sum32 = sum32 + fvecc(i)*dummy*t(i,2)*t(i,3); sum33 = sum33 + fvecc(i)*dummy*t(i,3)^2; end b(3) = sum22; b(5) = sum32; b(6) = sum33;
e04yb example results The test point is: 0.19000 -1.34000 0.88000 1st derivatives are consistent with residual values At the test point, lsqfun gives: Residuals 1st derivatives -0.0020 1.0000 -0.0406 -0.0027 -0.1076 1.0000 -0.0969 -0.0138 -0.2330 1.0000 -0.1785 -0.0412 -0.3785 1.0000 -0.3043 -0.1014 -0.5836 1.0000 -0.5144 -0.2338 -0.8689 1.0000 -0.9100 -0.5460 -1.3464 1.0000 -1.8098 -1.4076 -2.3739 1.0000 -4.7259 -4.7259 -2.9750 1.0000 -6.0762 -6.0762 -4.0132 1.0000 -7.8765 -7.8765 -5.3226 1.0000 -10.3970 -10.3970 -7.2917 1.0000 -14.1777 -14.1777 -10.5703 1.0000 -20.4789 -20.4789 -17.1274 1.0000 -33.0813 -33.0813 -36.8087 1.0000 -70.8885 -70.8885 and lsqhes gives the lower triangle of the matrix B 0.000e+00 0.000e+00 1.571e+04 0.000e+00 1.571e+04 1.571e+04