diff options
Diffstat (limited to 'tests/general_tests/fmincon')
33 files changed, 1130 insertions, 0 deletions
diff --git a/tests/general_tests/fmincon/fmincon_A.sce b/tests/general_tests/fmincon/fmincon_A.sce new file mode 100644 index 0000000..dd0df48 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_A.sce @@ -0,0 +1,20 @@ + +// Check if a user specifies coefficients of linear inequality contraints of the correct dimensions + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4,5,6]; +b = [7,9]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Expected Matrix of size (No of linear inequality constraints X No of Variables) or an Empty Matrix for Linear Inequality Constraint coefficient Matrix A +//at line 343 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b); +//at line 20 of exec file called by : +//exec fmincon_A.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b); diff --git a/tests/general_tests/fmincon/fmincon_Aeq.sce b/tests/general_tests/fmincon/fmincon_Aeq.sce new file mode 100644 index 0000000..17d8756 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_Aeq.sce @@ -0,0 +1,22 @@ + +// Check if a user specifies coefficients of linear equality contraints of the correct dimensions + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = [1,4,9]; +beq = [2]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Expected Matrix of size (No of linear equality constraints X No of Variables) or an Empty Matrix for Linear Equality Constraint coefficient Matrix Aeq +//at line 380 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq); +//at line 22 of exec file called by : +//exec fmincon_Aeq.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq); diff --git a/tests/general_tests/fmincon/fmincon_b1.sce b/tests/general_tests/fmincon/fmincon_b1.sce new file mode 100644 index 0000000..e43a866 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_b1.sce @@ -0,0 +1,20 @@ + +// Check if a user specifies upper bounds of linear inequality contraints in accordance with starting point dimensions and coefficient matrix of linear inequality constraints + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7,9,10,20]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Expected Row Vector (1 X number of linear inequality constraints) for b (4th Parameter) +//at line 368 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b); +//at line 20 of exec file called by : +//exec fmincon_b.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b); diff --git a/tests/general_tests/fmincon/fmincon_b2.sce b/tests/general_tests/fmincon/fmincon_b2.sce new file mode 100644 index 0000000..65cfc90 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_b2.sce @@ -0,0 +1,20 @@ + +// Check if a user specifies upper bounds of linear inequality contraints in accordance with starting point dimensions and coefficient matrix of linear inequality constraints + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = []; +b = [8,3]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Expected Row Vector (1 X number of linear inequality constraints) for b (4th Parameter) +//at line 368 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b); +//at line 20 of exec file called by : +//exec fmincon_b.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b); diff --git a/tests/general_tests/fmincon/fmincon_b3.sce b/tests/general_tests/fmincon/fmincon_b3.sce new file mode 100644 index 0000000..982ad69 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_b3.sce @@ -0,0 +1,20 @@ + +// Check if a user specifies upper bounds of linear inequality contraints in accordance with starting point dimensions and coefficient matrix of linear inequality constraints + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [5,8]; +b = []; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Expected Non empty Row/Column Vector for b (4th Parameter) for your Inputs +//at line 360 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b); +//at line 20 of exec file called by : +//exec fmincon_b3.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b); diff --git a/tests/general_tests/fmincon/fmincon_beq1.sce b/tests/general_tests/fmincon/fmincon_beq1.sce new file mode 100644 index 0000000..6133b77 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_beq1.sce @@ -0,0 +1,22 @@ + +// Check if a user specifies value of linear equality contraints in accordance with starting point dimensions and coefficient matrix of linear equality constraints + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = [1,4]; +beq = [2,6]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Expected Matrix of size (No of linear equality constraints X No of Variables) or an Empty Matrix for Linear Equality Constraint coefficient Matrix Aeq +//at line 380 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq); +//at line 22 of exec file called by : +//exec fmincon_Aeq.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq); diff --git a/tests/general_tests/fmincon/fmincon_beq2.sce b/tests/general_tests/fmincon/fmincon_beq2.sce new file mode 100644 index 0000000..7d2af88 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_beq2.sce @@ -0,0 +1,22 @@ + +// Check if a user specifies value of linear equality contraints in accordance with starting point dimensions and coefficient matrix of linear equality constraints + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = [2,6]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: As Linear Equality Constraint coefficient Matrix Aeq (5th parameter) is empty, beq (6th Parameter) should also be empty +//at line 392 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq); +//at line 22 of exec file called by : +//exec fmincon_beq2.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq); diff --git a/tests/general_tests/fmincon/fmincon_beq3.sce b/tests/general_tests/fmincon/fmincon_beq3.sce new file mode 100644 index 0000000..0605fdb --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_beq3.sce @@ -0,0 +1,22 @@ + +// Check if a user specifies value of linear equality contraints in accordance with starting point dimensions and coefficient matrix of linear equality constraints + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = [7,5]; +beq = []; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Expected Non empty Row/Column Vector for beq (6th Parameter) +//at line 397 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq); +//at line 22 of exec file called by : +//exec fmincon_beq3.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq); diff --git a/tests/general_tests/fmincon/fmincon_cputime.sce b/tests/general_tests/fmincon/fmincon_cputime.sce new file mode 100644 index 0000000..25e5aef --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_cputime.sce @@ -0,0 +1,56 @@ +// Example where maxiter exceeds the preset value + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq = [1,3] +beq= [5] +lb = [0 0] +ub = [2 1.5] + +function [c,ceq]=nlc(x) +c = [x(1)^2 - x(2)^2 + 0.5 , x(1)^2 + x(2)^2 - 2.5]; +ceq = []; +endfunction + +options = list("MaxIter", [150], "CpuTime", [0.005]) + +//Output +//Maximum CPU Time exceeded. Output may not be optimal. +// hessian = +// +// 1.79D-316 3.95D-323 +// 2.12D-314 4.34D+276 +// gradient = +// +// 3.96 2.97 +// lambda = +// +// lower: [0,0] +// upper: [0,0] +// ineqlin: [0,0,0,0,0,0] +// eqlin: 0 +// ineqnonlin: [0,0] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 0 +// Cpu_Time: 0.016 +// Objective_Evaluation: 1 +// Dual_Infeasibility: 1.4815294 +// exitflag = +// +// 2 +// fopt = +// +// 0. +// xopt = +// +// 1.98 +// 1.485 + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub, nlc, options) diff --git a/tests/general_tests/fmincon/fmincon_f.sce b/tests/general_tests/fmincon/fmincon_f.sce new file mode 100644 index 0000000..ec89f33 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_f.sce @@ -0,0 +1,18 @@ + +// Check if a user specifies function or not + +fun = []; +x0 = [1,2,3,4,5,6]; +A = [2,4,8,9,3,5]; +b = [1,5,7,3,9,6]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Expected type ["function"] for input argument f at input #1, but got "constant" instead. +//at line 56 of function Checktype called by : +//at line 297 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b); +//at line 18 of exec file called by : +//exec fmincon_f.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b); diff --git a/tests/general_tests/fmincon/fmincon_lb1.sce b/tests/general_tests/fmincon/fmincon_lb1.sce new file mode 100644 index 0000000..17b8eea --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_lb1.sce @@ -0,0 +1,24 @@ + +//Check if lower bound is a vector + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [2,4;5,9]; +ub = []; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Lower Bound (7th Parameter) should be a vector +//at line 422 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); +//at line 24 of exec file called by : +//exec fmincon_lb1.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/fmincon/fmincon_lb2.sce b/tests/general_tests/fmincon/fmincon_lb2.sce new file mode 100644 index 0000000..4420a12 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_lb2.sce @@ -0,0 +1,24 @@ + +//Check if lower bound is row vector of correct dimensions + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [2,4,9]; +ub = []; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Expected Row Vector (1 X number of Variables) for lower bound (7th Parameter) +//at line 430 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); +//at line 24 of exec file called by : +//exec fmincon_lb2.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/fmincon/fmincon_lb3.sce b/tests/general_tests/fmincon/fmincon_lb3.sce new file mode 100644 index 0000000..dc0b528 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_lb3.sce @@ -0,0 +1,24 @@ + +//Check if lower bound is column vector of correct dimensions + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [2;4;9]; +ub = []; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Expected Column Vector (number of Variables X 1) for lower bound (7th Parameter) +//at line 425 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); +//at line 24 of exec file called by : +//exec fmincon_lb3.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/fmincon/fmincon_lb4.sce b/tests/general_tests/fmincon/fmincon_lb4.sce new file mode 100644 index 0000000..643af5a --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_lb4.sce @@ -0,0 +1,24 @@ + +//Check if lower bound is not infinity + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [%inf,4]; +ub = []; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Value of Lower Bound can not be infinity +//at line 462 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); +//at line 24 of exec file called by : +//exec fmincon_lb4.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/fmincon/fmincon_lbub.sce b/tests/general_tests/fmincon/fmincon_lbub.sce new file mode 100644 index 0000000..d4c42ac --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_lbub.sce @@ -0,0 +1,24 @@ + +//Check if upper bound is greater than lower bound by atleast 1e-6 + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [1,0]; +ub = [0,1]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Difference between Upper Bound and Lower bound should be atleast > 10^6 for variable number= 1 +//at line 472 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); +//at line 24 of exec file called by : +//exec fmincon_lbub.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/fmincon/fmincon_logical1.sce b/tests/general_tests/fmincon/fmincon_logical1.sce new file mode 100644 index 0000000..9cbaf57 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical1.sce @@ -0,0 +1,45 @@ +// Example with objective function and inequality constraints + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; + +//Output +//Optimal Solution Found. +// hessian = +// +// 2. - 7.451D-09 +// - 7.451D-09 2. +// gradient = +// +// 1.0000000 1. +// lambda = +// +// lower: [0,0] +// upper: [0,0] +// ineqlin: [9.087D-09,2.424D-08,4.546D-09,5.596D-09,1,4.544D-09] +// eqlin: [0x0 constant] +// ineqnonlin: [0x0 constant] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 8 +// Cpu_Time: 0.112 +// Objective_Evaluation: 9 +// Dual_Infeasibility: 1.299D-11 +// exitflag = +// +// 0 +// fopt = +// +// 0.5 +// xopt = +// +// 0.5000000 +// 0.5000000 + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b) diff --git a/tests/general_tests/fmincon/fmincon_logical10.sce b/tests/general_tests/fmincon/fmincon_logical10.sce new file mode 100644 index 0000000..45ffdf3 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical10.sce @@ -0,0 +1,66 @@ +//Example where user provides hessian + +function y=f(x) +y=x(1)*x(2)+x(2)*x(3); +endfunction +//Starting point, linear constraints and variable bounds +x0=[0.1 , 0.1 , 0.1]; +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[]; +ub=[]; +//Nonlinear constraints +function [c,ceq]=nlc(x) +c = [x(1)^2 - x(2)^2 + x(3)^2 - 2 , x(1)^2 + x(2)^2 + x(3)^2 - 10]; +ceq = []; +endfunction + +//Hessian of the Lagrange Function +function y= lHess(x,obj,lambda) +y= obj*[0,1,0;1,0,1;0,1,0] + lambda(1)*[2,0,0;0,-2,0;0,0,2] + lambda(2)*[2,0,0;0,2,0;0,0,2] +endfunction + +//Options +options=list("MaxIter", [1500], "CpuTime", [500], "Hessian", lHess); + +//Output +//Optimal Solution Found. +// hessian = +// +// 1.4142136 1.72D-322 2.12D-314 +// 1. 0. 5.82D+252 +// 1. 1.4142136 1. +// gradient = +// +// 2.236068 - 3.1622776 2.236068 +// lambda = +// +// lower: [0,0,0] +// upper: [0,0,0] +// ineqlin: [0x0 constant] +// eqlin: [0x0 constant] +// ineqnonlin: [4.545D-09,0.7071068] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 23 +// Cpu_Time: 0.164 +// Objective_Evaluation: 24 +// Dual_Infeasibility: 6.124D-08 +// Message: "Optimal Solution Found" +// exitflag = +// +// 0 +// fopt = +// +// - 7.0710678 +// xopt = +// +// - 1.5811388 +// 2.236068 +// - 1.5811388 + +//Calling Ipopt +[xopt,fopt,exitflag,output,lambda,gradient,hessian] =fmincon(f, x0,A,b,Aeq,beq,lb,ub,nlc,options) diff --git a/tests/general_tests/fmincon/fmincon_logical11.sce b/tests/general_tests/fmincon/fmincon_logical11.sce new file mode 100644 index 0000000..0fe17ee --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical11.sce @@ -0,0 +1,46 @@ +// Example with objective function using log functions + +function y=fun(x) +y=log(x(1)+x(2)); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; + +//Output +//Optimal Solution Found. +// hessian = +// +// - 1.0000001 3.95D-323 +// - 1. - 1. +// gradient = +// +// 1. 1. +// lambda = +// +// lower: [0,0] +// upper: [0,0] +// ineqlin: [9.091D-09,1.384D-08,3.304D-09,4.768D-09,1,7.281D-09] +// eqlin: [0x0 constant] +// ineqnonlin: [0x0 constant] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 13 +// Cpu_Time: 0.228 +// Objective_Evaluation: 14 +// Dual_Infeasibility: 3.040D-09 +// Message: "Optimal Solution Found" +// exitflag = +// +// 0 +// fopt = +// +// - 9.091D-10 +// xopt = +// +// 0.1243037 +// 0.8756963 + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b) diff --git a/tests/general_tests/fmincon/fmincon_logical2.sce b/tests/general_tests/fmincon/fmincon_logical2.sce new file mode 100644 index 0000000..94e91f1 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical2.sce @@ -0,0 +1,47 @@ +// Example with objective function, equality and inequality constraints + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq = [1,3] +beq= [1.5] + +//Output +//Optimal Solution Found. +// hessian = +// +// 2. 0. +// 0. 2. +// gradient = +// +// 1.5 0.5000000 +// lambda = +// +// lower: [0,0] +// upper: [0,0] +// ineqlin: [9.089D-09,4.842D-08,6.059D-09,6.324D-09,2.0000001,3.637D-09] +// eqlin: 0.5000000 +// ineqnonlin: [0x0 constant] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 8 +// Cpu_Time: 0.092 +// Objective_Evaluation: 9 +// Dual_Infeasibility: 1.869D-11 +// exitflag = +// +// 0 +// fopt = +// +// 0.6250000 +// xopt = +// +// 0.7500000 +// 0.25 + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b,Aeq,beq) diff --git a/tests/general_tests/fmincon/fmincon_logical3.sce b/tests/general_tests/fmincon/fmincon_logical3.sce new file mode 100644 index 0000000..9c56f7b --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical3.sce @@ -0,0 +1,49 @@ +// Example with objective function, equality, inequality constraints and variable bounds + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq = [1,3] +beq= [5] +lb = [0 0] +ub = [2 1.5] + +//Output +//Optimal Solution Found. +// hessian = +// +// 2. 0. +// 0. 2. +// gradient = +// +// 0.9999999 3. +// lambda = +// +// lower: [1.820D-08,6.060D-09] +// upper: [6.059D-09,0.7267088] +// ineqlin: [0.3633544,7.251D-08,3.030D-09,3.463D-09,9.093D-09,9.096D-09] +// eqlin: -1.3633544 +// ineqnonlin: [0x0 constant] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 21 +// Cpu_Time: 0.2 +// Objective_Evaluation: 26 +// Dual_Infeasibility: 9.075D-11 +// exitflag = +// +// 0 +// fopt = +// +// 2.5 +// xopt = +// +// 0.5000000 +// 1.5 + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub) diff --git a/tests/general_tests/fmincon/fmincon_logical4.sce b/tests/general_tests/fmincon/fmincon_logical4.sce new file mode 100644 index 0000000..31221c8 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical4.sce @@ -0,0 +1,54 @@ +// Example with objective function, equality, inequality constraints, variable bounds and non linear function + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq = [1,3] +beq= [5] +lb = [0 0] +ub = [2 1.5] + +function [c,ceq]=nlc(x) +c = [x(1)^2 - x(2)^2 + 0.5 , x(1)^2 + x(2)^2 - 2.5]; +ceq = []; +endfunction + +//Output +//Optimal Solution Found. +// hessian = +// +// 3970695.7 3.311D-10 +// 3.311D-10 3970695.5 +// gradient = +// +// 1.0000000 3. +// lambda = +// +// lower: [1.818D-08,6.061D-09] +// upper: [6.061D-09,0.7272728] +// ineqlin: [0.3636363,7.273D-08,3.030D-09,3.463D-09,9.091D-09,9.091D-09] +// eqlin: -2.2698905 +// ineqnonlin: [6.061D-09,0.9062541] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 20 +// Cpu_Time: 0.4 +// Objective_Evaluation: 23 +// Dual_Infeasibility: 5.171D-09 +// exitflag = +// +// 0 +// fopt = +// +// 2.5 +// xopt = +// +// 0.5000000 +// 1.5 + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub,nlc) diff --git a/tests/general_tests/fmincon/fmincon_logical5.sce b/tests/general_tests/fmincon/fmincon_logical5.sce new file mode 100644 index 0000000..dbba29a --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical5.sce @@ -0,0 +1,56 @@ +// Example with objective function, equality, inequality constraints, variable bounds, non linear function and options + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq = [1,3] +beq= [5] +lb = [0 0] +ub = [2 1.5] + +function [c,ceq]=nlc(x) +c = [x(1)^2 - x(2)^2 + 0.5 , x(1)^2 + x(2)^2 - 2.5]; +ceq = []; +endfunction + +options = list("MaxIter", [1500], "CpuTime", [500]) + +//Output +//Optimal Solution Found. +// hessian = +// +// 3970695.7 3.311D-10 +// 3.311D-10 3970695.5 +// gradient = +// +// 1.0000000 3. +// lambda = +// +// lower: [1.818D-08,6.061D-09] +// upper: [6.061D-09,0.7272728] +// ineqlin: [0.3636363,7.273D-08,3.030D-09,3.463D-09,9.091D-09,9.091D-09] +// eqlin: -2.2698905 +// ineqnonlin: [6.061D-09,0.9062541] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 20 +// Cpu_Time: 0.4 +// Objective_Evaluation: 23 +// Dual_Infeasibility: 5.171D-09 +// exitflag = +// +// 0 +// fopt = +// +// 2.5 +// xopt = +// +// 0.5000000 +// 1.5 + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub, nlc, options) diff --git a/tests/general_tests/fmincon/fmincon_logical6.sce b/tests/general_tests/fmincon/fmincon_logical6.sce new file mode 100644 index 0000000..b99cca1 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical6.sce @@ -0,0 +1,45 @@ +// Example with objective function using sinusoidal functions + +function y=fun(x) +y=sin(x(1))+cos(x(2)); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; + +//Output +//Optimal Solution Found. +// hessian = +// +// 0.2129952 0. +// 0. 0.2129198 +// gradient = +// +// 0.9770613 - 0.9770613 +// lambda = +// +// lower: [0,0] +// upper: [0,0] +// ineqlin: [2.270D-08,1.202D-08,2.272D-09,3.316D-09,1.571D-08,0.9770613] +// eqlin: [0x0 constant] +// ineqnonlin: [0x0 constant] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 12 +// Cpu_Time: 0.132 +// Objective_Evaluation: 15 +// Dual_Infeasibility: 7.674D-10 +// exitflag = +// +// 0 +// fopt = +// +// - 0.4259168 +// xopt = +// +// - 0.2146019 +// 1.7853981 + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b) diff --git a/tests/general_tests/fmincon/fmincon_logical7.sce b/tests/general_tests/fmincon/fmincon_logical7.sce new file mode 100644 index 0000000..48d83b4 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical7.sce @@ -0,0 +1,45 @@ +// Example with objective function using exponential input + +function y=fun(x) +y=exp(x(2)*x(1)); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4]; +b=[2;1]; + +//Output +//Optimal Solution Found. +// hessian = +// +// 0.0000010 - 0.0000007 +// - 0.0000007 0.0000005 +// gradient = +// +// 7.127D-08 - 5.690D-08 +// lambda = +// +// lower: [0,0] +// upper: [0,0] +// ineqlin: [6.963D-09,2.501D-09] +// eqlin: [0x0 constant] +// ineqnonlin: [0x0 constant] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 15 +// Cpu_Time: 0.132 +// Objective_Evaluation: 16 +// Dual_Infeasibility: 8.073D-08 +// exitflag = +// +// 0 +// fopt = +// +// 1.500D-08 +// xopt = +// +// - 3.7925137 +// 4.7501487 + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b) diff --git a/tests/general_tests/fmincon/fmincon_logical8.sce b/tests/general_tests/fmincon/fmincon_logical8.sce new file mode 100644 index 0000000..7e24211 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical8.sce @@ -0,0 +1,60 @@ +// Example where user provides gradient of the objective function + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +function y= fGrad(x) +y= [2*x(1),2*x(2)]; +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq = [1,3] +beq= [5] +lb = [0 0] +ub = [2 1.5] + +function [c,ceq]=nlc(x) +c = [x(1)^2 - x(2)^2 + 0.5 , x(1)^2 + x(2)^2 - 2.5]; +ceq = []; +endfunction + +options = list("MaxIter", [150], "CpuTime", [500], "GradObj", fGrad) + +//Output +//Optimal Solution Found. +// hessian = +// +// 3970695.6 3.311D-10 +// 3.311D-10 3970695.4 +// gradient = +// +// 1.0000000 3. +// lambda = +// +// lower: [1.818D-08,6.061D-09] +// upper: [6.061D-09,0.7272728] +// ineqlin: [0.3636363,7.273D-08,3.030D-09,3.463D-09,9.091D-09,9.091D-09] +// eqlin: -2.2698905 +// ineqnonlin: [6.061D-09,0.9062542] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 20 +// Cpu_Time: 0.852 +// Objective_Evaluation: 23 +// Dual_Infeasibility: 1.884D-09 +// exitflag = +// +// 0 +// fopt = +// +// 2.5 +// xopt = +// +// 0.5000000 +// 1.5 + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub, nlc, options) diff --git a/tests/general_tests/fmincon/fmincon_logical9.sce b/tests/general_tests/fmincon/fmincon_logical9.sce new file mode 100644 index 0000000..129601b --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical9.sce @@ -0,0 +1,63 @@ +// Example where user provides gradient of the constraints + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq = [1,3] +beq= [5] +lb = [0 0] +ub = [2 1.5] + +function [c,ceq]=nlc(x) +c = [x(1)^2 - x(2)^2 + 0.5 , x(1)^2 + x(2)^2 - 2.5]; +ceq = []; +endfunction + +//Gradient of Non-Linear Constraints +function [cg,ceqg] = cGrad(x) +cg=[2*x(1) , -2*x(2); 2*x(1) , 2*x(2)]; +ceqg=[]; +endfunction + +options = list("MaxIter", [150], "CpuTime", [500], "GradCon", cGrad) + +//Output +//Optimal Solution Found. +// hessian = +// +// 3353468.3 3.95D-323 +// 0. 0. +// gradient = +// +// 1.0000000 3. +// lambda = +// +// lower: [1.818D-08,6.061D-09] +// upper: [6.061D-09,0.6917463] +// ineqlin: [0.3458731,7.273D-08,3.030D-09,3.463D-09,9.091D-09,9.091D-09] +// eqlin: -2.2520096 +// ineqnonlin: [6.061D-09,0.9061364] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 20 +// Cpu_Time: 0.34 +// Objective_Evaluation: 23 +// Dual_Infeasibility: 2.793D-09 +// Message: "Optimal Solution Found" +// exitflag = +// +// 0 +// fopt = +// +// 2.5 +// xopt = +// +// 0.5000000 +// 1.5 + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub, nlc, options) diff --git a/tests/general_tests/fmincon/fmincon_maxiter.sce b/tests/general_tests/fmincon/fmincon_maxiter.sce new file mode 100644 index 0000000..57d46b6 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_maxiter.sce @@ -0,0 +1,56 @@ +// Example where maxiter exceeds the preset value + +function y=fun(x) +y=x(1)*x(1)+x(2)*x(2); +endfunction + +x0 = [1,2]; +A=[1,1 ; 1,1/4 ; 1,-1 ; -1/4,-1 ; -1,-1 ; -1,1]; +b=[2;1;2;1;-1;2]; +Aeq = [1,3] +beq= [5] +lb = [0 0] +ub = [2 1.5] + +function [c,ceq]=nlc(x) +c = [x(1)^2 - x(2)^2 + 0.5 , x(1)^2 + x(2)^2 - 2.5]; +ceq = []; +endfunction + +options = list("MaxIter", [15], "CpuTime", [500]) + +//Output +//Maximum Number of Iterations Exceeded. Output may not be optimal. +// hessian = +// +// 335.44736 0. +// 0. 335.18088 +// gradient = +// +// 1.0000122 2.9999999 +// lambda = +// +// lower: [0.1999999,0.0666667] +// upper: [0.0666667,1803365.5] +// ineqlin: [486161.41,0.7135096,0.0332561,0.0381089,0.1000596,0.1000605] +// eqlin: -486461.97 +// ineqnonlin: [0.0666348,299.08034] +// eqnonlin: [0x0 constant] +// output = +// +// Iterations: 15 +// Cpu_Time: 0.252 +// Objective_Evaluation: 17 +// Dual_Infeasibility: 831041.12 +// exitflag = +// +// 1 +// fopt = +// +// 2.500006 +// xopt = +// +// 0.5000061 +// 1.5 + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub, nlc, options) diff --git a/tests/general_tests/fmincon/fmincon_ub1.sce b/tests/general_tests/fmincon/fmincon_ub1.sce new file mode 100644 index 0000000..acbe99a --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_ub1.sce @@ -0,0 +1,24 @@ + +//Check if upper bound is a vector + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [2,4]; +ub = [3,4;7,2]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Upper Bound (8th Parameter) should be a vector +//at line 445 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); +//at line 24 of exec file called by : +//exec fmincon_ub1.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/fmincon/fmincon_ub2.sce b/tests/general_tests/fmincon/fmincon_ub2.sce new file mode 100644 index 0000000..dc4d790 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_ub2.sce @@ -0,0 +1,24 @@ + +//Check if upper bound is row vector of correct dimensions + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [2,4]; +ub = [3,4,7]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Expected Row Vector (1 X number of Variables) for upper bound (8th Parameter) +//at line 453 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); +//at line 24 of exec file called by : +//exec fmincon_ub2.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/fmincon/fmincon_ub3.sce b/tests/general_tests/fmincon/fmincon_ub3.sce new file mode 100644 index 0000000..034abc7 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_ub3.sce @@ -0,0 +1,24 @@ + +//Check if lower bound is column vector of correct dimensions + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = [2,4]; +ub = [3;4;7]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Expected Column Vector (number of Variables X 1) for upper bound (8th Parameter) +//at line 448 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); +//at line 24 of exec file called by : +//exec fmincon_ub3.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/fmincon/fmincon_ub4.sce b/tests/general_tests/fmincon/fmincon_ub4.sce new file mode 100644 index 0000000..26dc579 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_ub4.sce @@ -0,0 +1,24 @@ + +//Check if upper bound is not -infinity + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1,2]; +A = [3,4]; +b = [7]; +Aeq = []; +beq = []; +lb = []; +ub = [-%inf,6]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Value of Upper Bound can not be negative infinity +//at line 467 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); +//at line 24 of exec file called by : +//exec fmincon_ub4.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b, Aeq, beq, lb, ub); diff --git a/tests/general_tests/fmincon/fmincon_x0a.sce b/tests/general_tests/fmincon/fmincon_x0a.sce new file mode 100644 index 0000000..68bf5f1 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_x0a.sce @@ -0,0 +1,20 @@ + +// Check if a user specifies a starting point or not + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = []; +A = [3,4]; +b = [7,9]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Expected Row Vector or Column Vector for x0 (Starting Point) or Starting Point cannot be Empty +//at line 305 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b); +//at line 20 of exec file called by : +//exec fmincon_x0a.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b); diff --git a/tests/general_tests/fmincon/fmincon_x0b.sce b/tests/general_tests/fmincon/fmincon_x0b.sce new file mode 100644 index 0000000..2b72f92 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_x0b.sce @@ -0,0 +1,20 @@ + +// Check if a user specifies a starting point of the correct dimensions with respect to the objective function + +function y=fun(x) +y=x(1)+x(2); +endfunction + +x0 = [1]; +A = [3,4]; +b = [7,9]; +options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", "OFF", "Hessian", "OFF"); + +//Error +//fmincon: Objective function and x0 did not match +//at line 318 of function fmincon called by : +//[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b); +//at line 20 of exec file called by : +//exec fmincon_x0b.sce + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0, A, b); |