diff options
Diffstat (limited to 'tests/general_tests')
48 files changed, 1103 insertions, 45 deletions
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) |