diff options
author | harpreet | 2016-04-16 12:12:15 +0530 |
---|---|---|
committer | harpreet | 2016-04-16 12:12:15 +0530 |
commit | 10e2e4d8b4a7592a8631ddac8e8d1664d6f0b9e3 (patch) | |
tree | 087af3ca1853d01afef58684b09b537597317023 | |
parent | 8484c85784b84cc3a9257f8d8065b3a8a7800628 (diff) | |
download | FOSSEE-Optimization-toolbox-10e2e4d8b4a7592a8631ddac8e8d1664d6f0b9e3.tar.gz FOSSEE-Optimization-toolbox-10e2e4d8b4a7592a8631ddac8e8d1664d6f0b9e3.tar.bz2 FOSSEE-Optimization-toolbox-10e2e4d8b4a7592a8631ddac8e8d1664d6f0b9e3.zip |
fmincon examples
57 files changed, 1436 insertions, 50 deletions
diff --git a/demos/lsqnonlin.dem.sce b/demos/lsqnonlin.dem.sce index a650e63..756dd4a 100644 --- a/demos/lsqnonlin.dem.sce +++ b/demos/lsqnonlin.dem.sce @@ -53,5 +53,5 @@ v = wm.*exp(-x(2)*tm) dy = [v , -x(1)*tm.*v] endfunction options = list("GradObj", "on") -[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,[],[],options) +[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,[],[]) //========= E N D === O F === D E M O =========// diff --git a/jar/scilab_en_US_help.jar b/jar/scilab_en_US_help.jar Binary files differindex bc44df7..f06df33 100644 --- a/jar/scilab_en_US_help.jar +++ b/jar/scilab_en_US_help.jar diff --git a/macros/fseminf.bin b/macros/fseminf.bin Binary files differnew file mode 100644 index 0000000..4616b57 --- /dev/null +++ b/macros/fseminf.bin diff --git a/macros/fseminf.sci b/macros/fseminf.sci new file mode 100644 index 0000000..2ffcab5 --- /dev/null +++ b/macros/fseminf.sci @@ -0,0 +1,322 @@ +// Copyright (C) 2015 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Author: Salman Anis, Harpreet Singh +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function [xopt,fopt,exitflag,output,lambda,gradient,hessian] = fseminf (varargin) + // Solves a multi-variable constrainted optimization problem + // + // Calling Sequence + // xopt = fseminf(fun,x0,ntheta,seminfcon) + // xopt = fseminf(fun,x0,ntheta,seminfcon,A,b) + // xopt = fseminf(fun,x0,ntheta,seminfcon,A,b,Aeq,beq) + // xopt = fseminf(fun,x0,ntheta,seminfcon,A,b,Aeq,beq,lb,ub) + // xopt = fseminf(fun,x0,ntheta,seminfcon,A,b,Aeq,beq,lb,ub,options) + // [xopt,fopt] = fseminf(.....) + // [xopt,fopt,exitflag]= fseminf(.....) + // [xopt,fopt,exitflag,output]= fseminf(.....) + // [xopt,fopt,exitflag,output,lambda]=fseminf(.....) + // [xopt,fopt,exitflag,output,lambda]=fseminf(.....) + // [xopt,fopt,exitflag,output,lambda]=fseminf(.....) + // + // Parameters + // fun : a function, representing the objective function of the problem + // x0 : a vector of doubles, containing the starting values of variables of size (1 X n) or (n X 1) where 'n' is the number of Variables + // ntheta : The number of semi-infinite constraints. + // seminfcon : a function that calculates the vector of nonlinear inequality constraints c, a vector of nonlinear equality constraints ceq, and ntheta semi-infinite constraints. See below for details. + // A : a matrix of double, represents the linear coefficients in the inequality constraints A⋅x ≤ b. + // b : a vector of double, represents the linear coefficients in the inequality constraints A⋅x ≤ b. + // Aeq : a matrix of double, represents the linear coefficients in the equality constraints Aeq⋅x = beq. + // beq : a vector of double, represents the linear coefficients in the equality constraints Aeq⋅x = beq. + // lb : a vector of double, contains lower bounds of the variables. + // ub : a vector of double, contains upper bounds of the variables. + // options : a list, containing the option for user to specify. See below for details. + + // xopt : a vector of double, the computed solution of the optimization problem. + // fopt : a double, the value of the function at x. + // exitflag : The exit status. See below for details. + // output : The structure consist of statistics about the optimization. See below for details. + // lambda : The structure consist of the Lagrange multipliers at the solution of problem. See below for details. + // + // Description + // Search the minimum of a constrained optimization problem specified by : + // Find the minimum of f(x) such that + // + // <latex> + // \begin{eqnarray} + // &\mbox{min}_{x} + // & f(x) \\ + // & \text{subject to} & A*x \leq b \\ + // & & Aeq*x \ = beq\\ + // & & lb \leq x \leq ub \\ + // & & c(x) \leq 0\\ + // & & ceq(x) \ = 0\\ + // & & K_i(x,w_i) \leq 0, 1 \leq i \leq n. + // \end{eqnarray} + // </latex> + // + // The routine calls Ipopt for solving the Constrained Optimization problem, Ipopt is a library written in C++. + // + // The options allows the user to set various parameters of the Optimization problem. + // It should be defined as type "list" and contains the following fields. + // <itemizedlist> + // <listitem>Syntax : options= list("MaxIter", [---], "CpuTime", [---], "GradObj", ---);</listitem> + // <listitem>MaxIter : a Scalar, containing the Maximum Number of Iteration that the solver should take.</listitem> + // <listitem>CpuTime : a Scalar, containing the Maximum amount of CPU Time that the solver should take.</listitem> + // <listitem>GradObj : a function, representing the gradient function of the Objective in Vector Form.</listitem> + // <listitem>Default Values : options = list("MaxIter", [3000], "CpuTime", [600]);</listitem> + // </itemizedlist> + // + // The exitflag allows to know the status of the optimization which is given back by Ipopt. + // <itemizedlist> + // <listitem>exitflag=0 : Optimal Solution Found </listitem> + // <listitem>exitflag=1 : Maximum Number of Iterations Exceeded. Output may not be optimal.</listitem> + // <listitem>exitflag=2 : Maximum amount of CPU Time exceeded. Output may not be optimal.</listitem> + // <listitem>exitflag=3 : Stop at Tiny Step.</listitem> + // <listitem>exitflag=4 : Solved To Acceptable Level.</listitem> + // <listitem>exitflag=5 : Converged to a point of local infeasibility.</listitem> + // </itemizedlist> + // + // For more details on exitflag see the ipopt documentation, go to http://www.coin-or.org/Ipopt/documentation/ + // + // The output data structure contains detailed informations about the optimization process. + // It has type "struct" and contains the following fields. + // <itemizedlist> + // <listitem>output.Iterations: The number of iterations performed during the search</listitem> + // <listitem>output.Cpu_Time: The total cpu-time spend during the search</listitem> + // <listitem>output.Objective_Evaluation: The number of Objective Evaluations performed during the search</listitem> + // <listitem>output.Dual_Infeasibility: The Dual Infeasiblity of the final soution</listitem> + // </itemizedlist> + // + // The lambda data structure contains the Lagrange multipliers at the end + // of optimization. In the current version the values are returned only when the the solution is optimal. + // It has type "struct" and contains the following fields. + // <itemizedlist> + // <listitem>lambda.lower: The Lagrange multipliers for the lower bound constraints.</listitem> + // <listitem>lambda.upper: The Lagrange multipliers for the upper bound constraints.</listitem> + // <listitem>lambda.eqlin: The Lagrange multipliers for the linear equality constraints.</listitem> + // <listitem>lambda.ineqlin: The Lagrange multipliers for the linear inequality constraints.</listitem> + // <listitem>lambda.eqnonlin: The Lagrange multipliers for the non-linear equality constraints.</listitem> + // <listitem>lambda.ineqnonlin: The Lagrange multipliers for the non-linear inequality constraints.</listitem> + // </itemizedlist> + // + // Examples + // function [y] = obj(x) + // y = (x-1)^2; + // endfunction + // function [c, ceq, K1, s] = seminfcon(x,s) + // // No finite nonlinear inequality and equality constraints + // c = []; + // ceq = []; + // // Sample set + // if isnan(s) + // // Initial sampling interval + // s = [0.01 0]; + // end + // t = 0:s(1):1; + // // Evaluate the semi-infinite constraint + // K1 = (x - 0.5) - (t - 0.5).^2; + // endfunction + // x = fseminf(obj,0.2,1,seminfcon) + // + // Authors + // Salman Anis, Harpreet Singh + + + //To check the number of input and output arguments + [lhs , rhs] = argn(); + + //To check the number of arguments given by the user + if ( rhs<4 | rhs==5 | rhs==7 | rhs>13 ) then + errmsg = msprintf(gettext("%s: Unexpected number of input arguments : %d provided while it should be 4,6,8,10,11"), "fseminf", rhs); + error(errmsg) + end + + //Storing the Input Parameters + _fun = varargin(1); + x0 = varargin(2); + ntheta = varargin(3); + seminfcon = varargin(4); + nbVar = size(x0,'*'); + + if(nbVar == 0) then + errmsg = msprintf(gettext("%s: Cannot determine the number of variables because input initial guess is empty"), "lsqcurvefit"); + error(errmsg); + end + + A = []; + b = []; + Aeq = []; + beq = []; + lb = []; + ub = []; + nlc = []; + param = list(); + + if (rhs>4) then + A = varargin(5); + b = varargin(6); + end + + if (rhs>6) then + Aeq = varargin(7); + beq = varargin(8); + end + + if (rhs>8) then + lb = varargin(9); + ub = varargin(10); + end + + if (rhs>10) then + param = varargin(10); + end + + if (size(lb,2)==0) then + lb = repmat(-%inf,nbVar,1); + end + + if (size(ub,2)==0) then + ub = repmat(%inf,nbVar,1); + end + + //Check type of variables + Checktype("fseminf", _fun, "fun", 1, "function") + Checktype("fseminf", x0, "x0", 2, "constant") + Checktype("fseminf", ntheta, "ntheta", 3, "constant") + Checktype("fseminf", seminfcon, "seminfcon", 4, ["function","constant"]) + Checktype("fseminf", A, "A", 5, "constant") + Checktype("fseminf", b, "b", 6, "constant") + Checktype("fseminf", Aeq, "Aeq", 7, "constant") + Checktype("fseminf", beq, "beq", 8, "constant") + Checktype("fseminf", lb, "lb", 9, "constant") + Checktype("fseminf", ub, "ub", 10, "constant") + Checktype("fseminf", param, "param", 10, "list") + + //To check the user entry for options and storing it + for i = 1:(size(param))/2 + select convstr(param(2*i-1),'l') + case "maxiter" then + Checktype("fseminf", param(2*i), "maxiter", 10, "constant") + options(2) = param(2*i); //Setting the maximum number of iterations as per user entry + case "cputime" then + Checktype("fseminf", param(2*i), "cputime", 10, "constant") + options(4) = param(2*i); //Setting the maximum CPU time as per user entry + case "gradobj" then + Checktype("fseminf", param(2*i), "gradobj", 10, "string") + if(convstr(param(2*i),'l') == "on") then + function dy = graObj(x) + + endfunction + end + else + errmsg = msprintf(gettext("%s: Unrecognized parameter name %s."), "fmincon", param(2*i-1)); + error(errmsg); + end + end + + //To check and convert the 2nd Input argument (x0) to a row vector + if((size(x0,1)~=1) & (size(x0,2)~=1)) then + errmsg = msprintf(gettext("%s: Expected Vector for initial guess"), "fseminf"); + error(errmsg); + end + + if(size(x0,2)==1) then + x0=x0(:); + end + + //To check the match between fun (1st Parameter) and x0 (2nd Parameter) + if(execstr('init=_fun(x0)','errcatch')==21) then + errmsg = msprintf(gettext("%s: Objective function and x0 did not match"), "fseminf"); + error(errmsg); + end + + //Check the size of inequality constraint which should be equal to the number of variables + if ( size(A,2) ~= nbVar & size(A,2) ~= 0) then + errmsg = msprintf(gettext("%s: The number of columns in A must be the same as the number of elements of x0"), "fseminf"); + error(errmsg); + end + + nbConInEq = size(A,"r"); + + //Check the size of equality constraint which should be equal to the number of variables + if ( size(Aeq,2) ~= nbVar & size(Aeq,2) ~= 0 ) then + errmsg = msprintf(gettext("%s: The number of columns in Aeq must be the same as the number of elements of f"), "fseminf"); + error(errmsg); + end + + b = b(:); + beq = beq(:); + lb = lb(:); + ub = ub(:); + + //To check the contents of lb & ub + for i = 1:nbVar + if(ub(i)<lb(i)) then + errmsg = msprintf(gettext("%s: Problem has inconsistent variable bounds"), "fseminf"); + error(errmsg); + end + end + + if(typeof(seminfcon) == "function") + sample_S = %nan + if(execstr('[sample_c,sample_ceq,sample_K,sample_S] = seminfcon(x0,sample_S)','errcatch')==21) + errmsg = msprintf(gettext("%s: Semi-Infinite Constraint function & x0 did not match"), "fseminf"); + error(errmsg); + end + [sample_c, sample_ceq, sample_K, sample_S] = seminfcon(x0,sample_S); + + if (size(sample_c,1)~=1 & size(sample_c,1)~=0) then + errmsg = msprintf(gettext("%s: c in seminfcon should be a row vector or empty matrix"), "fseminf"); + error(errmsg) + end + + if (size(sample_ceq,1)~=1 & size(sample_ceq,1)~=0) then + errmsg = msprintf(gettext("%s: ceq in seminfcon should be a row vector or empty matrix"), "fseminf"); + error(errmsg) + end + + if (size(sample_K,"r")~=ntheta) then + errmsg = msprintf(gettext("%s: Number of rows in K should be equal to ntheta"), "fseminf"); + error(errmsg) + end + + if (size(sample_S,"c")~=2) then + errmsg = msprintf(gettext("%s: Number of columns in sampling interval should be equal to 2"), "fseminf"); + error(errmsg) + end + end + + ierr = execstr('init=_fun(x0)', "errcatch") + if ierr <> 0 then + lamsg = lasterror(); + lclmsg = "%s: Error while evaluating the function: ""%s""\n"; + error(msprintf(gettext(lclmsg), "fseminf", lamsg)); + end + + S = %nan; + + ierr = execstr('init=seminfcon(x0,S)', "errcatch") + if ierr <> 0 then + lamsg = lasterror(); + lclmsg = "%s: Error while evaluating the function: ""%s""\n"; + error(msprintf(gettext(lclmsg), "fseminf", lamsg)); + end + + function [c, ceq] = _seminfcon(x) + [c, ceq, K, S] = seminfcon(x,S) + K_max = max(K,"c"); + c= [c;K_max]; + ceq = ceq; + endfunction + + //Calling the fmincon function for solving the above problem + [xopt,fopt,exitflag,output,lambda,gradient] = fmincon(_fun,x0,A,b,Aeq,beq,lb,ub,_seminfcon,param) + +endfunction Binary files differdiff --git a/macros/lsqnonlin.bin b/macros/lsqnonlin.bin Binary files differindex 32e8417..c90bc0d 100644 --- a/macros/lsqnonlin.bin +++ b/macros/lsqnonlin.bin diff --git a/macros/lsqnonlin.sci b/macros/lsqnonlin.sci index 22df579..823d088 100644 --- a/macros/lsqnonlin.sci +++ b/macros/lsqnonlin.sci @@ -175,7 +175,7 @@ function [xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin (va ub = varargin(4); end - if ( rhs<7 | size(varargin(5)) ==0 ) then + if ( rhs<5 | size(varargin(5)) ==0 ) then param = list(); else param =varargin(5); @@ -240,7 +240,7 @@ function [xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin (va //To check the match between fun (1st Parameter) and x0 (2nd Parameter) if(execstr('init=_fun(x0)','errcatch')==21) then - errmsg = msprintf(gettext("%s: Objective function and x0 did not match"), "fmincon"); + errmsg = msprintf(gettext("%s: Objective function and x0 did not match"), "lsqnonlin"); error(errmsg); end @@ -309,7 +309,12 @@ function [xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin (va options(6) = __fGrad; - [xopt,fopt,exitflag,output,lambda_fmincon,gradient] = fmincon(__fun,x0,[],[],[],[],lb,ub,[],options); + function [c, ceq] = nlc(x) + c = []; + ceq = []; + endfunction + + [xopt,fopt,exitflag,output,lambda_fmincon,gradient] = fmincon(__fun,x0,[],[],[],[],lb,ub,nlc,options); lambda = struct("lower", lambda_fmincon.lower,"upper",lambda_fmincon.upper); diff --git a/macros/names b/macros/names index dc01f55..21c7d4e 100644 --- a/macros/names +++ b/macros/names @@ -8,6 +8,7 @@ fminbnd fmincon fminimax fminunc +fseminf linprog lsqlin lsqnonlin diff --git a/sci_gateway/cpp/sci_ipoptfmincon.cpp b/sci_gateway/cpp/sci_ipoptfmincon.cpp index f19bbeb..c19687d 100644 --- a/sci_gateway/cpp/sci_ipoptfmincon.cpp +++ b/sci_gateway/cpp/sci_ipoptfmincon.cpp @@ -147,7 +147,7 @@ int sci_solveminconp(char *fname) ///////// Initialize the IpoptApplication and process the options ///////// ApplicationReturnStatus status; - status = app->Initialize(); + status = app->Initialize(); if (status != Solve_Succeeded) { sciprint("\n*** Error during initialization!\n"); diff --git a/tests/general_tests/fminbnd/fminbnd_logical10.sce b/tests/general_tests/fminbnd/fminbnd_logical10.sce new file mode 100644 index 0000000..d36072a --- /dev/null +++ b/tests/general_tests/fminbnd/fminbnd_logical10.sce @@ -0,0 +1,30 @@ + +function y = fun(x) + y = -1/(1-x*x); +endfunction +x1 = [0]; +x2 = [1000]; + +//Output +// +//Error in step computation (regularization becomes too large?)! +// lambda = +// +// lower: [0x0 constant] +// upper: [0x0 constant] +// output = +// +// Iterations: 108 +// Cpu_Time: 0.064 +// Message: "Error in step computation (regularization becomes too large?)!" +// exitflag = +// +// 10 +// fopt = +// +// [] +// xopt = +// +// [] +[xopt,fopt,exitflag,output,lambda] = fminbnd (fun, x1, x2) + diff --git a/tests/general_tests/fminbnd/fminbnd_logical11.sce b/tests/general_tests/fminbnd/fminbnd_logical11.sce new file mode 100644 index 0000000..0681d30 --- /dev/null +++ b/tests/general_tests/fminbnd/fminbnd_logical11.sce @@ -0,0 +1,31 @@ + +function y = fun(x) + y = -sqrt(x*x); +endfunction +x1 = [-10]; +x2 = [-5]; + +//Output +// +//Optimal Solution Found. +// lambda = +// +// lower: 1.0000018 +// upper: 0.0000018 +// output = +// +// Iterations: 5 +// Cpu_Time: 0.036 +// Objective_Evaluation: 6 +// Dual_Infeasibility: 2.390D-11 +// Message: "Optimal Solution Found" +// exitflag = +// +// 0 +// fopt = +// +// - 9.9999909 +// xopt = +// +// - 9.9999909 +[xopt,fopt,exitflag,output,lambda] = fminbnd (fun, x1, x2) diff --git a/tests/general_tests/fminbnd/fminbnd_logical12.sce b/tests/general_tests/fminbnd/fminbnd_logical12.sce new file mode 100644 index 0000000..0613aa8 --- /dev/null +++ b/tests/general_tests/fminbnd/fminbnd_logical12.sce @@ -0,0 +1,31 @@ + +function y = fun(x) + y = log(x); +endfunction +x1 = [-10]; +x2 = [0]; + +//Output +// +//Optimal Solution Found. +// lambda = +// +// lower: 0.0000018 +// upper: 0.0000018 +// output = +// +// Iterations: 4 +// Cpu_Time: 0.028 +// Objective_Evaluation: 5 +// Dual_Infeasibility: 0 +// Message: "Optimal Solution Found" +// exitflag = +// +// 0 +// fopt = +// +// 0. +// xopt = +// +// - 0.7727429 +[xopt,fopt,exitflag,output,lambda] = fminbnd (fun, x1, x2) diff --git a/tests/general_tests/fminbnd/fminbnd_logical13.sce b/tests/general_tests/fminbnd/fminbnd_logical13.sce new file mode 100644 index 0000000..64debea --- /dev/null +++ b/tests/general_tests/fminbnd/fminbnd_logical13.sce @@ -0,0 +1,32 @@ + +function y = fun(x) + y = -sqrt(x^3); +endfunction +x1 = [-10]; +x2 = [-5]; + +//Output +// +//Optimal Solution Found. +// lambda = +// +// lower: 0.0000036 +// upper: 0.0000036 +// output = +// +// Iterations: 4 +// Cpu_Time: 0.028 +// Objective_Evaluation: 5 +// Dual_Infeasibility: 0 +// Message: "Optimal Solution Found" +// exitflag = +// +// 0 +// fopt = +// +// 0. +// xopt = +// +// - 5.4668503 + +[xopt,fopt,exitflag,output,lambda] = fminbnd (fun, x1, x2) diff --git a/tests/general_tests/fminbnd/fminbnd_logical3.sce b/tests/general_tests/fminbnd/fminbnd_logical3.sce new file mode 100644 index 0000000..2687733 --- /dev/null +++ b/tests/general_tests/fminbnd/fminbnd_logical3.sce @@ -0,0 +1,33 @@ + +function y = fun(x) + y = -1/x; +endfunction +x1 = [0]; +x2 = [1.5]; + +//Output +// +//Stop at Tiny Step +// lambda = +// +// lower: 1.235D+14 +// upper: 0.0000061 +// output = +// +// Iterations: 1.663D+09 +// Cpu_Time: 0.112 +// Objective_Evaluation: 34 +// Dual_Infeasibility: 1747.2543 +// Message: "Stop at Tiny Step" +// exitflag = +// +// 3 +// fopt = +// +// - 11111111. +// xopt = +// +// 1.000D-07 + +[xopt,fopt,exitflag,output,lambda] = fminbnd (fun, x1, x2) + diff --git a/tests/general_tests/fminbnd/fminbnd_logical4.sce b/tests/general_tests/fminbnd/fminbnd_logical4.sce new file mode 100644 index 0000000..69c6960 --- /dev/null +++ b/tests/general_tests/fminbnd/fminbnd_logical4.sce @@ -0,0 +1,33 @@ + +function y = fun(x) + y = 1/x; +endfunction +x1 = [-10]; +x2 = [0]; + +//Output +// +//Optimal Solution Found. +// lambda = +// +// lower: 0.0000013 +// upper: 1.235D+14 +// output = +// +// Iterations: 18 +// Cpu_Time: 0.096 +// Objective_Evaluation: 19 +// Dual_Infeasibility: 0.0232831 +// Message: "Optimal Solution Found" +// exitflag = +// +// 0 +// fopt = +// +// - 11111339. +// xopt = +// +// - 1.000D-07 + +[xopt,fopt,exitflag,output,lambda] = fminbnd (fun, x1, x2) + diff --git a/tests/general_tests/fminbnd/fminbnd_logical5.sce b/tests/general_tests/fminbnd/fminbnd_logical5.sce new file mode 100644 index 0000000..0e9f670 --- /dev/null +++ b/tests/general_tests/fminbnd/fminbnd_logical5.sce @@ -0,0 +1,31 @@ + +function y = fun(x) + y = -1/(x*x); +endfunction +x1 = [0]; +x2 = [1.5]; + +//Output +// +//Error in step computation (regularization becomes too large?)! +// lambda = +// +// lower: [0x0 constant] +// upper: [0x0 constant] +// output = +// +// Iterations: 108 +// Cpu_Time: 0.06 +// Message: "Error in step computation (regularization becomes too large?)!" +// exitflag = +// +// 10 +// fopt = +// +// [] +// xopt = +// +// [] + +[xopt,fopt,exitflag,output,lambda] = fminbnd (fun, x1, x2) + diff --git a/tests/general_tests/fminbnd/fminbnd_logical6.sce b/tests/general_tests/fminbnd/fminbnd_logical6.sce new file mode 100644 index 0000000..d030a86 --- /dev/null +++ b/tests/general_tests/fminbnd/fminbnd_logical6.sce @@ -0,0 +1,31 @@ + +function y = fun(x) + y = 1/(x*x); +endfunction +x1 = [-10]; +x2 = [0]; + +//Output +// +//Error in step computation (regularization becomes too large?)! +// lambda = +// +// lower: [0x0 constant] +// upper: [0x0 constant] +// output = +// +// Iterations: 108 +// Cpu_Time: 0.06 +// Message: "Error in step computation (regularization becomes too large?)!" +// exitflag = +// +// 10 +// fopt = +// +// [] +// xopt = +// +// [] + +[xopt,fopt,exitflag,output,lambda] = fminbnd (fun, x1, x2) + diff --git a/tests/general_tests/fminbnd/fminbnd_logical7.sce b/tests/general_tests/fminbnd/fminbnd_logical7.sce new file mode 100644 index 0000000..8207f92 --- /dev/null +++ b/tests/general_tests/fminbnd/fminbnd_logical7.sce @@ -0,0 +1,33 @@ + +function y = fun(x) + y = exp(x); +endfunction +x1 = [-1000]; +x2 = [1000]; + +//Output +// +//Optimal Solution Found. +// lambda = +// +// lower: 9.183D-09 +// upper: 9.001D-09 +// output = +// +// Iterations: 10 +// Cpu_Time: 0.064 +// Objective_Evaluation: 11 +// Dual_Infeasibility: 0.0000455 +// Message: "Optimal Solution Found" +// exitflag = +// +// 0 +// fopt = +// +// 0.0000455 +// xopt = +// +// - 9.9979363 + +[xopt,fopt,exitflag,output,lambda] = fminbnd (fun, x1, x2) + diff --git a/tests/general_tests/fminbnd/fminbnd_logical8.sce b/tests/general_tests/fminbnd/fminbnd_logical8.sce new file mode 100644 index 0000000..fa0785c --- /dev/null +++ b/tests/general_tests/fminbnd/fminbnd_logical8.sce @@ -0,0 +1,33 @@ + +function y = fun(x) + y = sin(x)*exp(x); +endfunction +x1 = [-1000]; +x2 = [1000]; + +//Output +// +//Optimal Solution Found. +// lambda = +// +// lower: 9.183D-09 +// upper: 9.001D-09 +// output = +// +// Iterations: 10 +// Cpu_Time: 0.064 +// Objective_Evaluation: 11 +// Dual_Infeasibility: 0.0000455 +// Message: "Optimal Solution Found" +// exitflag = +// +// 0 +// fopt = +// +// 0.0000455 +// xopt = +// +// - 9.9979363 + +[xopt,fopt,exitflag,output,lambda] = fminbnd (fun, x1, x2) + diff --git a/tests/general_tests/fminbnd/fminbnd_logical9.sce b/tests/general_tests/fminbnd/fminbnd_logical9.sce new file mode 100644 index 0000000..7581feb --- /dev/null +++ b/tests/general_tests/fminbnd/fminbnd_logical9.sce @@ -0,0 +1,30 @@ + +function y = fun(x) + y = -1/(x*x); +endfunction +x1 = [0]; +x2 = [1000]; + +//Output +// +//Error in step computation (regularization becomes too large?)! +// lambda = +// +// lower: [0x0 constant] +// upper: [0x0 constant] +// output = +// +// Iterations: 108 +// Cpu_Time: 0.064 +// Message: "Error in step computation (regularization becomes too large?)!" +// exitflag = +// +// 10 +// fopt = +// +// [] +// xopt = +// +// [] +[xopt,fopt,exitflag,output,lambda] = fminbnd (fun, x1, x2) + diff --git a/tests/general_tests/fmincon/fmincon_logical12.sce b/tests/general_tests/fmincon/fmincon_logical12.sce index 325cd2c..48715a1 100644 --- a/tests/general_tests/fmincon/fmincon_logical12.sce +++ b/tests/general_tests/fmincon/fmincon_logical12.sce @@ -1,14 +1,13 @@ - // Example with objective function and inequality constraints +// Example with objective function and inequality constraints function y=fun(x) - k=1 - y=0 - for i = 1:20 - y = y + exp(x(i)) - end + y=-sum(exp(x)) endfunction + x0 = [repmat(1,1,20)]; A=[-1,-5,-3 repmat(0,1,17); -0.5,-2.5 -1.5 repmat(0,1,17);]; b=[-100 -50]'; + lb = repmat(0,1,20); -k = 0 -[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[]) +ub = repmat(10,1,20); + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,ub) diff --git a/tests/general_tests/fmincon/fmincon_logical13.sce b/tests/general_tests/fmincon/fmincon_logical13.sce index 3c6b87d..5c1246c 100644 --- a/tests/general_tests/fmincon/fmincon_logical13.sce +++ b/tests/general_tests/fmincon/fmincon_logical13.sce @@ -1,10 +1,7 @@ // Example with objective function and inequality constraints function y=fun(x) - y=0 - for i = 1:20 - y = y + exp(x(i)) - end + y=-sum(exp(x)); endfunction x0 = repmat(1,1,20); diff --git a/tests/general_tests/fmincon/fmincon_logical14.sce b/tests/general_tests/fmincon/fmincon_logical14.sce index 2febc72..33e108f 100644 --- a/tests/general_tests/fmincon/fmincon_logical14.sce +++ b/tests/general_tests/fmincon/fmincon_logical14.sce @@ -1,10 +1,7 @@ -// Example with objective function and inequality constraints +// Example with objective function, inequality constraints and non linear constraints function y=fun(x) - y=0 - for i = 1:20 - y = y + exp(x(i)) - end + y=-sum(exp(x)) endfunction x0 = repmat(1,1,20); @@ -15,11 +12,7 @@ b=[-100 -50]'; //Nonlinear constraints function [c,ceq]=nlc(x) - cfor = 0; - for i = 1:20 - cfor = cfor + 2*exp(x(i)) - end - c = [ cfor + 1]; + c = [ sum(2*exp(x)) + 1]; ceq = []; endfunction diff --git a/tests/general_tests/fmincon/fmincon_logical15.sce b/tests/general_tests/fmincon/fmincon_logical15.sce new file mode 100644 index 0000000..a95cf8d --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical15.sce @@ -0,0 +1,19 @@ +// Example with objective function, inequality constraints and non linear constraints + +function y=fun(x) + y = -prod(exp(x)) +endfunction + +x0 = repmat(1,1,20); +lb = repmat(0,1,20); + +A=[-1,-5,-3 repmat(0,1,17); -0.5,-2.5 -1.5 repmat(0,1,17);]; +b=[-100 -50]'; + +//Nonlinear constraints +function [c,ceq]=nlc(x) + c = [ sum(2*exp(x)) + 1]; + ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[],nlc) diff --git a/tests/general_tests/fmincon/fmincon_logical16.sce b/tests/general_tests/fmincon/fmincon_logical16.sce new file mode 100644 index 0000000..fa28254 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical16.sce @@ -0,0 +1,18 @@ +// Example with objective function, inequality constraints and non linear constraints + +function y=fun(x) + y = exp(prod(x)); +endfunction + +x0 = repmat(1,1,20); +lb = repmat(0,1,20); + +A=[-1,-5,-3 repmat(0,1,17); -0.5,-2.5 -1.5 repmat(0,1,17);]; +b=[-100 -50]'; + +function [c,ceq]=nlc(x) + c = [ sum(2*exp(x)) + 1]; + ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[],nlc) diff --git a/tests/general_tests/fmincon/fmincon_logical17.sce b/tests/general_tests/fmincon/fmincon_logical17.sce new file mode 100644 index 0000000..520b095 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical17.sce @@ -0,0 +1,13 @@ +// Example with log objective function, inequality constraints + +function y=fun(x) + y = sum(log(x)) +endfunction + +x0 = repmat(1,1,20); +lb = repmat(0,1,20); + +A=[-1,-5,-3 repmat(0,1,17); -0.5,-2.5 -1.5 repmat(0,1,17);]; +b=[-100 -50]'; + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[]) diff --git a/tests/general_tests/fmincon/fmincon_logical18.sce b/tests/general_tests/fmincon/fmincon_logical18.sce new file mode 100644 index 0000000..9fdd9d6 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical18.sce @@ -0,0 +1,14 @@ +// Example with log objective function, inequality constraints + +function y=fun(x) + y = sum(log(x(i))) +endfunction + +x0 = repmat(1,1,20); +lb = repmat(0,1,20); +ub = repmat(10,1,20); + +A=[-1,-5,-3 repmat(0,1,17); -0.5,-2.5 -1.5 repmat(0,1,17);]; +b=[-100 -50]'; + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,ub) diff --git a/tests/general_tests/fmincon/fmincon_logical19.sce b/tests/general_tests/fmincon/fmincon_logical19.sce new file mode 100644 index 0000000..733e1ec --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical19.sce @@ -0,0 +1,19 @@ +// Example with log objective function, inequality constraints and non linear constraints + +function y=fun(x) + y=sum(log(x)) +endfunction + +x0 = repmat(1,1,3); +lb = repmat(0,1,3); +ub = repmat(10,1,3); + +A=[-1,-5,-3;]; +b=[-100]'; + +function [c,ceq]=nlc(x) +c = [- 0.5*log(x(1)) - 2.5*log(x(2)) - 1.5*log(x(3)) + 50]; +ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,ub) diff --git a/tests/general_tests/fmincon/fmincon_logical20.sce b/tests/general_tests/fmincon/fmincon_logical20.sce new file mode 100644 index 0000000..6a2d92a --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical20.sce @@ -0,0 +1,19 @@ +// Example with log objective function, inequality constraints and non linear constraints + +function y=fun(x) + y = sum(log(x)) +endfunction + +x0 = repmat(1,1,3); +lb = repmat(0,1,3); +ub = repmat(10,1,3); + +A=[-1,-5,-3;]; +b=[-100]'; + +function [c,ceq]=nlc(x) +c = [log(x(1)) + log(x(2)) + log(x(3)) + 1]; +ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,ub) diff --git a/tests/general_tests/fmincon/fmincon_logical21.sce b/tests/general_tests/fmincon/fmincon_logical21.sce new file mode 100644 index 0000000..856fa3a --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical21.sce @@ -0,0 +1,18 @@ +// Example with log objective function, inequality constraints + +function y=fun(x) + y = -prod(log(x)) +endfunction + +x0 = repmat(1,1,20); +lb = repmat(0,1,20); + +A=[-1,-5,-3 repmat(0,1,17); -0.5,-2.5 -1.5 repmat(0,1,17);]; +b=[-100 -50]'; + +function [c,ceq]=nlc(x) + c = [ sum(log(x)) + 1]; + ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[],nlc) diff --git a/tests/general_tests/fmincon/fmincon_logical22.sce b/tests/general_tests/fmincon/fmincon_logical22.sce new file mode 100644 index 0000000..037e9b1 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical22.sce @@ -0,0 +1,19 @@ +// Example with log objective function, inequality constraints + +function y=fun(x) + y = log(prod(x)); +endfunction + +x0 = repmat(1,1,20); +lb = repmat(0,1,20); + +A=[-1,-5,-3 repmat(0,1,17); -0.5,-2.5 -1.5 repmat(0,1,17);]; +b=[-100 -50]'; + +//Nonlinear constraints +function [c,ceq]=nlc(x) + c = [ sum(log(x)) + 1]; + ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[],nlc) diff --git a/tests/general_tests/fmincon/fmincon_logical23.sce b/tests/general_tests/fmincon/fmincon_logical23.sce new file mode 100644 index 0000000..59bd9dd --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical23.sce @@ -0,0 +1,11 @@ +// Example with objective function and inequality constraints +function y=fun(x) + y=sum((sin(x)).^2 + (cos(x)).^2) +endfunction + +x0 = [repmat(1,1,3)]; +A=[-1,-5,-3; -0.5,-2.5 -1.5;]; +b=[-100 -50]'; +lb = repmat(0,1,3); + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[]) diff --git a/tests/general_tests/fmincon/fmincon_logical24.sce b/tests/general_tests/fmincon/fmincon_logical24.sce new file mode 100644 index 0000000..7f3c42e --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical24.sce @@ -0,0 +1,16 @@ +// Example with objective function and inequality constraints +function y=fun(x) + y=sum((sin(x)).^2 + (cos(x)).^2) +endfunction + +x0 = [repmat(1,1,3)]; +A=[-1,-5,-3; -0.5,-2.5 -1.5;]; +b=[-100 -50]'; +lb = repmat(0,1,3); + +function [c,ceq]=nlc(x) + c = [ -sum((sin(x)).^2 + (cos(x)).^2) + 1.5]; + ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[],nlc) diff --git a/tests/general_tests/fmincon/fmincon_logical25.sce b/tests/general_tests/fmincon/fmincon_logical25.sce new file mode 100644 index 0000000..bc94124 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical25.sce @@ -0,0 +1,12 @@ +// Example with objective function and inequality constraints +function y=fun(x) + y=sum(1/(cos(x))) +endfunction + +x0 = [repmat(1,1,3)]; +A=[-1,-5,-3;]; +b=[-100]'; +lb = repmat(0,1,3); +ub = repmat(10,1,3); + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,ub) diff --git a/tests/general_tests/fmincon/fmincon_logical26.sce b/tests/general_tests/fmincon/fmincon_logical26.sce new file mode 100644 index 0000000..9535ed8 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical26.sce @@ -0,0 +1,17 @@ +// Example with objective function and inequality constraints +function y=fun(x) + y=sum(sin(x)) +endfunction + +x0 = [repmat(1,1,3)]; +A=[-1,-5,-3; -0.5,-2.5 -1.5;]; +b=[-100 -50]'; +lb = repmat(0,1,3); + +//Nonlinear constraints +function [c,ceq]=nlc(x) + c = [ sum(sin(x)./cos(x)) + 1]; + ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[],nlc) diff --git a/tests/general_tests/fmincon/fmincon_logical27.sce b/tests/general_tests/fmincon/fmincon_logical27.sce new file mode 100644 index 0000000..2934f2a --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical27.sce @@ -0,0 +1,19 @@ +// Example with objective function, inequality constraints and non linear constraints + +function y=fun(x) + y = -prod(tan(x)) +endfunction + +x0 = repmat(1,1,20); +lb = repmat(0,1,20); + +A=[-1,-5,-3 repmat(0,1,17); -0.5,-2.5 -1.5 repmat(0,1,17);]; +b=[-100 -50]'; + +//Nonlinear constraints +function [c,ceq]=nlc(x) + c = [ sum(2*cos(x)) - 1]; + ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[],nlc) diff --git a/tests/general_tests/fmincon/fmincon_logical28.sce b/tests/general_tests/fmincon/fmincon_logical28.sce new file mode 100644 index 0000000..08f3b06 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical28.sce @@ -0,0 +1,19 @@ +// Example with objective function, inequality constraints and non linear constraints + +function y=fun(x) + y = cos(prod(x)) +endfunction + +x0 = repmat(1,1,20); +lb = repmat(0,1,20); + +A=[-1,-5,-3 repmat(0,1,17); -0.5,-2.5 -1.5 repmat(0,1,17);]; +b=[-100 -50]'; + +//Nonlinear constraints +function [c,ceq]=nlc(x) + c = [ sum(2*cos(x)) - 1]; + ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[],nlc) diff --git a/tests/general_tests/fmincon/fmincon_logical29.sce b/tests/general_tests/fmincon/fmincon_logical29.sce new file mode 100644 index 0000000..649d7b0 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical29.sce @@ -0,0 +1,11 @@ +// Example with objective function and inequality constraints +function y=fun(x) + y=sum(exp(x) + cos(x).^2) +endfunction + +x0 = [repmat(1,1,3)]; +A=[-1,-5,-3; -0.5,-2.5 -1.5;]; +b=[-100 -50]'; +lb = repmat(0,1,3); + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[]) diff --git a/tests/general_tests/fmincon/fmincon_logical30.sce b/tests/general_tests/fmincon/fmincon_logical30.sce new file mode 100644 index 0000000..cbcbac2 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical30.sce @@ -0,0 +1,17 @@ +// Example with objective function and inequality constraints +function y=fun(x) + y=sum(log(x) + cos(x).^2) +endfunction + +x0 = [repmat(1,1,3)]; +A=[-1,-5,-3; -0.5,-2.5 -1.5;]; +b=[-100 -50]'; +lb = repmat(0,1,3); + +//Nonlinear constraints +function [c,ceq]=nlc(x) + c = [ -sum((sin(x)).^2 + (cos(x)).^2) + 1.5]; + ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[],nlc) diff --git a/tests/general_tests/fmincon/fmincon_logical31.sce b/tests/general_tests/fmincon/fmincon_logical31.sce new file mode 100644 index 0000000..4adfa1d --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical31.sce @@ -0,0 +1,17 @@ +// Example with objective function and inequality constraints +function y=fun(x) + y=sum(1/exp(x)) +endfunction + +x0 = [repmat(1,1,3)]; +A=[-1,-5,-3;]; +b=[-100]; +lb = repmat(0,1,3); + +//Nonlinear constraints +function [c,ceq]=nlc(x) + c = [ sum(log(x)) - 10]; + ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[],nlc) diff --git a/tests/general_tests/fmincon/fmincon_logical32.sce b/tests/general_tests/fmincon/fmincon_logical32.sce new file mode 100644 index 0000000..3684613 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical32.sce @@ -0,0 +1,17 @@ +// Example with objective function and inequality constraints +function y=fun(x) + y=sum(sin(x)) +endfunction + +x0 = [repmat(3,1,3)]; +A=[-1,-5,-3; -0.5,-2.5 -1.5;]; +b=[-100 -50]'; +lb = repmat(0,1,3); + +//Nonlinear constraints +function [c,ceq]=nlc(x) + c = [ sum(exp(x)./log(x)) - 10]; + ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[],nlc) diff --git a/tests/general_tests/fmincon/fmincon_logical33.sce b/tests/general_tests/fmincon/fmincon_logical33.sce new file mode 100644 index 0000000..468aa94 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical33.sce @@ -0,0 +1,19 @@ +// Example with objective function, inequality constraints and non linear constraints + +function y=fun(x) + y = -prod(tan(x)) +endfunction + +x0 = repmat(1,1,20); +lb = repmat(0,1,20); + +A=[-1,-5,-3 repmat(0,1,17); -0.5,-2.5 -1.5 repmat(0,1,17);]; +b=[-100 -50]'; + +//Nonlinear constraints +function [c,ceq]=nlc(x) + c = [ sum(2*exp(x)) - 1]; + ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[],nlc) diff --git a/tests/general_tests/fmincon/fmincon_logical34.sce b/tests/general_tests/fmincon/fmincon_logical34.sce new file mode 100644 index 0000000..b615af8 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical34.sce @@ -0,0 +1,19 @@ +// Example with objective function, inequality constraints and non linear constraints + +function y=fun(x) + y = exp(prod(x)) +endfunction + +x0 = repmat(1,1,20); +lb = repmat(0,1,20); + +A=[-1,-5,-3 repmat(0,1,17); -0.5,-2.5 -1.5 repmat(0,1,17);]; +b=[-100 -50]'; + +//Nonlinear constraints +function [c,ceq]=nlc(x) + c = [ sum(2*cos(x) + log(x)) - 1]; + ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,A,b,[],[],lb,[],nlc) diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_A1.sce b/tests/general_tests/lsqnonlin/lsqnonlin_A1.sce deleted file mode 100644 index 1c2128b..0000000 --- a/tests/general_tests/lsqnonlin/lsqnonlin_A1.sce +++ /dev/null @@ -1,19 +0,0 @@ -// Check for elements in A -C = [2 0; - -1 1; - 0 2] -d = [1 - 0 - -1]; -A = [10 -2 0; - -2 10 0]; -b = [4 - -4]; - -//Error -//lsqlin: The number of columns in A must be the same as the number of columns in C -//at line 213 of function lsqlin called by : -//[xopt,resnorm,residual,exitflag,output,lambda] = lsqlin(C,d,A,b) - -[xopt,resnorm,residual,exitflag,output,lambda] = lsqlin(C,d,A,b) - diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_input1.sce b/tests/general_tests/lsqnonlin/lsqnonlin_input1.sce new file mode 100644 index 0000000..6a4ec5a --- /dev/null +++ b/tests/general_tests/lsqnonlin/lsqnonlin_input1.sce @@ -0,0 +1,29 @@ +// Check for the number of input arguments + +function y=yth(t, x) +y = x(1)*exp(-x(2)*t) +endfunction +// we have the m measures (ti, yi): +m = 10; +tm = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5]'; +ym = [0.79, 0.59, 0.47, 0.36, 0.29, 0.23, 0.17, 0.15, 0.12, 0.08]'; +// measure weights (here all equal to 1...) +wm = ones(m,1); +// and we want to find the parameters x such that the model fits the given +// data in the least square sense: +// +// minimize f(x) = sum_i wm(i)^2 ( yth(tm(i),x) - ym(i) )^2 +// initial parameters guess +x0 = [1.5; 0.8]; +// in the first examples, we define the function fun and dfun +// in scilab language +function y=myfun(x, tm, ym, wm) +y = wm.*( yth(tm, x) - ym ) +endfunction + +//Error +//lsqnonlin: Unexpected number of input arguments : 1 provided while should be in the set of [2 4 5] +//at line 139 of function lsqnonlin called by : +//[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun) + +[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun) diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_input2.sce b/tests/general_tests/lsqnonlin/lsqnonlin_input2.sce new file mode 100644 index 0000000..67a0b4b --- /dev/null +++ b/tests/general_tests/lsqnonlin/lsqnonlin_input2.sce @@ -0,0 +1,29 @@ +// Check for the number of input arguments + +function y=yth(t, x) +y = x(1)*exp(-x(2)*t) +endfunction +// we have the m measures (ti, yi): +m = 10; +tm = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5]'; +ym = [0.79, 0.59, 0.47, 0.36, 0.29, 0.23, 0.17, 0.15, 0.12, 0.08]'; +// measure weights (here all equal to 1...) +wm = ones(m,1); +// and we want to find the parameters x such that the model fits the given +// data in the least square sense: +// +// minimize f(x) = sum_i wm(i)^2 ( yth(tm(i),x) - ym(i) )^2 +// initial parameters guess +x0 = [1.5; 0.8]; +// in the first examples, we define the function fun and dfun +// in scilab language +function y=myfun(x, tm, ym, wm) +y = wm.*( yth(tm, x) - ym ) +endfunction + +//Error +//lsqnonlin: Unexpected number of input arguments : 6 provided while should be in the set of [2 4 5] +//at line 139 of function lsqnonlin called by : +//[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,[],[],[],[]) + +[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,[],[],[],[]) diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_lb1.sce b/tests/general_tests/lsqnonlin/lsqnonlin_lb1.sce new file mode 100644 index 0000000..9d24f57 --- /dev/null +++ b/tests/general_tests/lsqnonlin/lsqnonlin_lb1.sce @@ -0,0 +1,32 @@ +// Check for elements in lb + +function y=yth(t, x) +y = x(1)*exp(-x(2)*t) +endfunction +// we have the m measures (ti, yi): +m = 10; +tm = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5]'; +ym = [0.79, 0.59, 0.47, 0.36, 0.29, 0.23, 0.17, 0.15, 0.12, 0.08]'; +// measure weights (here all equal to 1...) +wm = ones(m,1); +// and we want to find the parameters x such that the model fits the given +// data in the least square sense: +// +// minimize f(x) = sum_i wm(i)^2 ( yth(tm(i),x) - ym(i) )^2 +// initial parameters guess +x0 = [1.5; 0.8]; +// in the first examples, we define the function fun and dfun +// in scilab language +function y=myfun(x, tm, ym, wm) +y = wm.*( yth(tm, x) - ym ) +endfunction + +lb = [0 0 0] +ub = [10 10] + +//Error +//lsqnonlin: The Lower Bound is not equal to the number of variables +//at line 246 of function lsqnonlin called by : +//[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,lb,ub) + +[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,lb,ub) diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_lb2.sce b/tests/general_tests/lsqnonlin/lsqnonlin_lb2.sce new file mode 100644 index 0000000..f5ea221 --- /dev/null +++ b/tests/general_tests/lsqnonlin/lsqnonlin_lb2.sce @@ -0,0 +1,32 @@ +// Check for elements in lb + +function y=yth(t, x) +y = x(1)*exp(-x(2)*t) +endfunction +// we have the m measures (ti, yi): +m = 10; +tm = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5]'; +ym = [0.79, 0.59, 0.47, 0.36, 0.29, 0.23, 0.17, 0.15, 0.12, 0.08]'; +// measure weights (here all equal to 1...) +wm = ones(m,1); +// and we want to find the parameters x such that the model fits the given +// data in the least square sense: +// +// minimize f(x) = sum_i wm(i)^2 ( yth(tm(i),x) - ym(i) )^2 +// initial parameters guess +x0 = [1.5; 0.8]; +// in the first examples, we define the function fun and dfun +// in scilab language +function y=myfun(x, tm, ym, wm) +y = wm.*( yth(tm, x) - ym ) +endfunction + +lb = [0] +ub = [10 10] + +//Error +//lsqnonlin: The Lower Bound is not equal to the number of variables +//at line 246 of function lsqnonlin called by : +//[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,lb,ub) + +[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,lb,ub) diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_lbub.sce b/tests/general_tests/lsqnonlin/lsqnonlin_lbub.sce new file mode 100644 index 0000000..eabc439 --- /dev/null +++ b/tests/general_tests/lsqnonlin/lsqnonlin_lbub.sce @@ -0,0 +1,32 @@ +// Check for elements in lb and ub + +function y=yth(t, x) +y = x(1)*exp(-x(2)*t) +endfunction +// we have the m measures (ti, yi): +m = 10; +tm = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5]'; +ym = [0.79, 0.59, 0.47, 0.36, 0.29, 0.23, 0.17, 0.15, 0.12, 0.08]'; +// measure weights (here all equal to 1...) +wm = ones(m,1); +// and we want to find the parameters x such that the model fits the given +// data in the least square sense: +// +// minimize f(x) = sum_i wm(i)^2 ( yth(tm(i),x) - ym(i) )^2 +// initial parameters guess +x0 = [1.5; 0.8]; +// in the first examples, we define the function fun and dfun +// in scilab language +function y=myfun(x, tm, ym, wm) +y = wm.*( yth(tm, x) - ym ) +endfunction + +lb = [10 10] +ub = [0 0] + +//Error +//lsqnonlin: Problem has inconsistent variable bounds +//at line 270 of function lsqnonlin called by : +//[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,lb,ub) + +[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,lb,ub) diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_logical1.sce b/tests/general_tests/lsqnonlin/lsqnonlin_logical1.sce index aef546f..ab4a7c7 100644 --- a/tests/general_tests/lsqnonlin/lsqnonlin_logical1.sce +++ b/tests/general_tests/lsqnonlin/lsqnonlin_logical1.sce @@ -1,7 +1,10 @@ -function retF = testmyfun(x) +function [y,dy] = testmyfun(x) km = [1:10]'; - retF = 2 + 2*km-exp(km*x(1))-exp(km*x(2)); + y = 2 + 2*km-exp(km*x(1))-exp(km*x(2)); endfunction -x0 = [0.3 0.4]' -[x,resnorm] = lsqnonlin(testmyfun,x0) +x0 = [0.2 0.2]' + +options = list("GradObj","off") + +[x,resnorm,residual] = lsqnonlin(testmyfun,x0,[],[],options) diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_maxiter.sce b/tests/general_tests/lsqnonlin/lsqnonlin_maxiter.sce new file mode 100644 index 0000000..3c13ff4 --- /dev/null +++ b/tests/general_tests/lsqnonlin/lsqnonlin_maxiter.sce @@ -0,0 +1,65 @@ +// Check for the maximum iteration + +function y=yth(t, x) +y = x(1)*exp(-x(2)*t) +endfunction +// we have the m measures (ti, yi): +m = 10; +tm = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5]'; +ym = [0.79, 0.59, 0.47, 0.36, 0.29, 0.23, 0.17, 0.15, 0.12, 0.08]'; +// measure weights (here all equal to 1...) +wm = ones(m,1); +// and we want to find the parameters x such that the model fits the given +// data in the least square sense: +// +// minimize f(x) = sum_i wm(i)^2 ( yth(tm(i),x) - ym(i) )^2 +// initial parameters guess +x0 = [1.5; 0.8]; +// in the first examples, we define the function fun and dfun +// in scilab language +function y=myfun(x, tm, ym, wm) +y = wm.*( yth(tm, x) - ym ) +endfunction + +options = list("MaxIter",10) + +//Error +//Maximum Number of Iterations Exceeded. Output may not be optimal. +// gradient = +// +// 512.91855 - 4714.171 +// lambda = +// +// lower: [0,0] +// upper: [0,0] +// output = +// +// Iterations: 10 +// Cpu_Time: 0.12 +// Objective_Evaluation: 11 +// Dual_Infeasibility: 4714.171 +// Message: "Maximum Number of Iterations Exceeded. Output may not be optimal" +// exitflag = +// +// 1 +// residual = +// +// 4.8006782 +// 5.767661 +// 6.7598659 +// 7.8617282 +// 9.0596638 +// 10.40234 +// 11.920987 +// 13.599744 +// 15.516066 +// 17.701171 +// resnorm = +// +// 1235.2439 +// xopt = +// +// 4.9162235 +// - 0.5142398 + +[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,[],[],options) diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_param1.sce b/tests/general_tests/lsqnonlin/lsqnonlin_param1.sce new file mode 100644 index 0000000..e303099 --- /dev/null +++ b/tests/general_tests/lsqnonlin/lsqnonlin_param1.sce @@ -0,0 +1,32 @@ +// Check for the params + +function y=yth(t, x) +y = x(1)*exp(-x(2)*t) +endfunction +// we have the m measures (ti, yi): +m = 10; +tm = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5]'; +ym = [0.79, 0.59, 0.47, 0.36, 0.29, 0.23, 0.17, 0.15, 0.12, 0.08]'; +// measure weights (here all equal to 1...) +wm = ones(m,1); +// and we want to find the parameters x such that the model fits the given +// data in the least square sense: +// +// minimize f(x) = sum_i wm(i)^2 ( yth(tm(i),x) - ym(i) )^2 +// initial parameters guess +x0 = [1.5; 0.8]; +// in the first examples, we define the function fun and dfun +// in scilab language +function y=myfun(x, tm, ym, wm) +y = wm.*( yth(tm, x) - ym ) +endfunction + +options = 0; + +//Error +//lsqnonlin: Expected type ["list"] for input argument param at input #5, but got "constant" instead. +//at line 56 of function Checktype called by : +//at line 186 of function lsqnonlin called by : +//[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,[],[],options) + +[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,[],[],options) diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_param2.sce b/tests/general_tests/lsqnonlin/lsqnonlin_param2.sce new file mode 100644 index 0000000..659294a --- /dev/null +++ b/tests/general_tests/lsqnonlin/lsqnonlin_param2.sce @@ -0,0 +1,31 @@ +// Check for the params + +function y=yth(t, x) +y = x(1)*exp(-x(2)*t) +endfunction +// we have the m measures (ti, yi): +m = 10; +tm = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5]'; +ym = [0.79, 0.59, 0.47, 0.36, 0.29, 0.23, 0.17, 0.15, 0.12, 0.08]'; +// measure weights (here all equal to 1...) +wm = ones(m,1); +// and we want to find the parameters x such that the model fits the given +// data in the least square sense: +// +// minimize f(x) = sum_i wm(i)^2 ( yth(tm(i),x) - ym(i) )^2 +// initial parameters guess +x0 = [1.5; 0.8]; +// in the first examples, we define the function fun and dfun +// in scilab language +function y=myfun(x, tm, ym, wm) +y = wm.*( yth(tm, x) - ym ) +endfunction + +options = list("Maxiter") + +//Error +//lsqnonlin: Size of parameters should be even +//at line 190 of function lsqnonlin called by : +//[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,[],[],options) + +[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,[],[],options) diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_ub1.sce b/tests/general_tests/lsqnonlin/lsqnonlin_ub1.sce new file mode 100644 index 0000000..37ca056 --- /dev/null +++ b/tests/general_tests/lsqnonlin/lsqnonlin_ub1.sce @@ -0,0 +1,32 @@ +// Check for elements in ub + +function y=yth(t, x) +y = x(1)*exp(-x(2)*t) +endfunction +// we have the m measures (ti, yi): +m = 10; +tm = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5]'; +ym = [0.79, 0.59, 0.47, 0.36, 0.29, 0.23, 0.17, 0.15, 0.12, 0.08]'; +// measure weights (here all equal to 1...) +wm = ones(m,1); +// and we want to find the parameters x such that the model fits the given +// data in the least square sense: +// +// minimize f(x) = sum_i wm(i)^2 ( yth(tm(i),x) - ym(i) )^2 +// initial parameters guess +x0 = [1.5; 0.8]; +// in the first examples, we define the function fun and dfun +// in scilab language +function y=myfun(x, tm, ym, wm) +y = wm.*( yth(tm, x) - ym ) +endfunction + +lb = [0 0] +ub = [10 10 10] + +//Error +//lsqnonlin: The Upper Bound is not equal to the number of variables +//at line 252 of function lsqnonlin called by : +//[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,lb,ub) + +[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,lb,ub) diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_ub2.sce b/tests/general_tests/lsqnonlin/lsqnonlin_ub2.sce new file mode 100644 index 0000000..2206b2f --- /dev/null +++ b/tests/general_tests/lsqnonlin/lsqnonlin_ub2.sce @@ -0,0 +1,32 @@ +// Check for elements in ub + +function y=yth(t, x) +y = x(1)*exp(-x(2)*t) +endfunction +// we have the m measures (ti, yi): +m = 10; +tm = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5]'; +ym = [0.79, 0.59, 0.47, 0.36, 0.29, 0.23, 0.17, 0.15, 0.12, 0.08]'; +// measure weights (here all equal to 1...) +wm = ones(m,1); +// and we want to find the parameters x such that the model fits the given +// data in the least square sense: +// +// minimize f(x) = sum_i wm(i)^2 ( yth(tm(i),x) - ym(i) )^2 +// initial parameters guess +x0 = [1.5; 0.8]; +// in the first examples, we define the function fun and dfun +// in scilab language +function y=myfun(x, tm, ym, wm) +y = wm.*( yth(tm, x) - ym ) +endfunction + +lb = [0 0] +ub = [10] + +//Error +//lsqnonlin: The Upper Bound is not equal to the number of variables +//at line 252 of function lsqnonlin called by : +//[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,lb,ub) + +[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0,lb,ub) diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_x01.sce b/tests/general_tests/lsqnonlin/lsqnonlin_x01.sce new file mode 100644 index 0000000..41dfb26 --- /dev/null +++ b/tests/general_tests/lsqnonlin/lsqnonlin_x01.sce @@ -0,0 +1,29 @@ +// Check if the x0 is column matrix + +function y=yth(t, x) +y = x(1)*exp(-x(2)*t) +endfunction +// we have the m measures (ti, yi): +m = 10; +tm = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5]'; +ym = [0.79, 0.59, 0.47, 0.36, 0.29, 0.23, 0.17, 0.15, 0.12, 0.08]'; +// measure weights (here all equal to 1...) +wm = ones(m,1); +// and we want to find the parameters x such that the model fits the given +// data in the least square sense: +// +// minimize f(x) = sum_i wm(i)^2 ( yth(tm(i),x) - ym(i) )^2 +// initial parameters guess +x0 = [1.5 0.8]; +// in the first examples, we define the function fun and dfun +// in scilab language +function y=myfun(x, tm, ym, wm) +y = wm.*( yth(tm, x) - ym ) +endfunction + +//Error +//lsqcurvefit: Initial Guess should be a column matrix +//at line 156 of function lsqnonlin called by : +//[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0') + +[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0) diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_x02.sce b/tests/general_tests/lsqnonlin/lsqnonlin_x02.sce new file mode 100644 index 0000000..00df3d4 --- /dev/null +++ b/tests/general_tests/lsqnonlin/lsqnonlin_x02.sce @@ -0,0 +1,29 @@ +// Check for elements in x0 + +function y=yth(t, x) +y = x(1)*exp(-x(2)*t) +endfunction +// we have the m measures (ti, yi): +m = 10; +tm = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5]'; +ym = [0.79, 0.59, 0.47, 0.36, 0.29, 0.23, 0.17, 0.15, 0.12, 0.08]'; +// measure weights (here all equal to 1...) +wm = ones(m,1); +// and we want to find the parameters x such that the model fits the given +// data in the least square sense: +// +// minimize f(x) = sum_i wm(i)^2 ( yth(tm(i),x) - ym(i) )^2 +// initial parameters guess +x0 = [1.5]; +// in the first examples, we define the function fun and dfun +// in scilab language +function y=myfun(x, tm, ym, wm) +y = wm.*( yth(tm, x) - ym ) +endfunction + +//Error +//lsqnonlin: Objective function and x0 did not match +//at line 233 of function lsqnonlin called by : +//[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0) + +[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0) |