$$\mathrm{Minimize}F\left(x\right)=\sum _{i=1}^{m}{\left[{f}_{i}\left(x\right)\right]}^{2}$$ |
Input Parameters
Output Parameters
$$B\left(x\right)=\sum _{i=1}^{m}{f}_{i}\left(x\right){G}_{i}\left(x\right)\text{,}$$ |
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, | n < 1${\mathbf{n}}<1$, |
or | m < n${\mathbf{m}}<{\mathbf{n}}$, |
or | lw < 8 × n + 2 × n × n + 2 × m × n + 3 × m$\mathit{lw}<8\times {\mathbf{n}}+2\times {\mathbf{n}}\times {\mathbf{n}}+2\times {\mathbf{m}}\times {\mathbf{n}}+3\times {\mathbf{m}}$, when n > 1${\mathbf{n}}>1$, |
or | lw < 11 + 5 × m$\mathit{lw}<11+5\times {\mathbf{m}}$, when n = 1${\mathbf{n}}=1$. |
Open in the MATLAB editor: nag_opt_lsq_uncon_mod_deriv2_easy_example
function nag_opt_lsq_uncon_mod_deriv2_easy_example m = int64(15); x = [0.5; 1; 1.5]; x = [0.5; 1; 1.5]; 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]]; user = {y, t, 3}; [xOut, fsumsq, user, ifail] = ... nag_opt_lsq_uncon_mod_deriv2_easy(m, @lsfun2, @lshes2, x, 'user', user) function [fvecc, fjacc, user] = lsfun2(m, n, xc, ljc, user) fvecc = zeros(m, 1); fjacc = zeros(ljc, n); for i = 1:double(m) denom = xc(2)*user{2}(i,2) + xc(3)*user{2}(i,3); fvecc(i) = xc(1) + user{2}(i,1)/denom - user{1}(i); fjacc(i,1) = 1.0d0; dummy = -1.0d0/(denom*denom); fjacc(i,2) = user{2}(i,1)*user{2}(i,2)*dummy; fjacc(i,3) = user{2}(i,1)*user{2}(i,3)*dummy; end function [b, user] = lshes2(m, n, fvecc, xc, lb, user) b = zeros(lb, 1); sum22 = 0.0d0; sum32 = 0.0d0; sum33 = 0.0d0; for i = 1:double(m) dummy = 2.0d0*user{2}(i,1)/(xc(2)*user{2}(i,2)+xc(3)*user{2}(i,3))^3; sum22 = sum22 + fvecc(i)*dummy*user{2}(i,2)^2; sum32 = sum32 + fvecc(i)*dummy*user{2}(i,2)*user{2}(i,3); sum33 = sum33 + fvecc(i)*dummy*user{2}(i,3)^2; end b(3) = sum22; b(5) = sum32; b(6) = sum33;
xOut = 0.0824 1.1330 2.3437 fsumsq = 0.0082 user = [1x15 double] [15x3 double] [3] ifail = 0
Open in the MATLAB editor: e04hy_example
function e04hy_example m = int64(15); x = [0.5; 1; 1.5]; x = [0.5; 1; 1.5]; 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]]; user = {y, t, 3}; [xOut, fsumsq, user, ifail] = e04hy(m, @lsfun2, @lshes2, x, 'user', user) function [fvecc, fjacc, user] = lsfun2(m, n, xc, ljc, user) fvecc = zeros(m, 1); fjacc = zeros(ljc, n); for i = 1:double(m) denom = xc(2)*user{2}(i,2) + xc(3)*user{2}(i,3); fvecc(i) = xc(1) + user{2}(i,1)/denom - user{1}(i); fjacc(i,1) = 1.0d0; dummy = -1.0d0/(denom*denom); fjacc(i,2) = user{2}(i,1)*user{2}(i,2)*dummy; fjacc(i,3) = user{2}(i,1)*user{2}(i,3)*dummy; end function [b, user] = lshes2(m, n, fvecc, xc, lb, user) b = zeros(lb, 1); sum22 = 0.0d0; sum32 = 0.0d0; sum33 = 0.0d0; for i = 1:double(m) dummy = 2.0d0*user{2}(i,1)/(xc(2)*user{2}(i,2)+xc(3)*user{2}(i,3))^3; sum22 = sum22 + fvecc(i)*dummy*user{2}(i,2)^2; sum32 = sum32 + fvecc(i)*dummy*user{2}(i,2)*user{2}(i,3); sum33 = sum33 + fvecc(i)*dummy*user{2}(i,3)^2; end b(3) = sum22; b(5) = sum32; b(6) = sum33;
xOut = 0.0824 1.1330 2.3437 fsumsq = 0.0082 user = [1x15 double] [15x3 double] [3] ifail = 0