diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/general_tests/fmincon/fmincon_logical10.sce | 47 | ||||
-rw-r--r-- | tests/general_tests/fmincon/fmincon_logical12.sce | 14 | ||||
-rw-r--r-- | tests/general_tests/fmincon/fmincon_logical13.sce | 19 | ||||
-rw-r--r-- | tests/general_tests/fmincon/fmincon_logical14.sce | 26 | ||||
-rw-r--r-- | tests/general_tests/fmincon/fmincon_logical4.sce | 2 | ||||
-rw-r--r-- | tests/general_tests/fmincon/fmincon_logical7.sce | 2 | ||||
-rw-r--r-- | tests/general_tests/lsqnonlin/lsqnonlin_A1.sce | 19 | ||||
-rw-r--r-- | tests/general_tests/lsqnonlin/lsqnonlin_logical1.sce | 7 |
8 files changed, 94 insertions, 42 deletions
diff --git a/tests/general_tests/fmincon/fmincon_logical10.sce b/tests/general_tests/fmincon/fmincon_logical10.sce index 45ffdf3..999ee2c 100644 --- a/tests/general_tests/fmincon/fmincon_logical10.sce +++ b/tests/general_tests/fmincon/fmincon_logical10.sce @@ -13,7 +13,7 @@ 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]; +c = [x(1)^2 - x(2)^2 + x(3)^2 - 2 ; x(1)^2 + x(2)^2 + x(3)^2 - 10]'; ceq = []; endfunction @@ -23,44 +23,11 @@ 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 endfunction //Options -options=list("MaxIter", [1500], "CpuTime", [500], "Hessian", lHess); +options=list("MaxIter", [100], "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 +//Calling fmincon [xopt,fopt,exitflag,output,lambda,gradient,hessian] =fmincon(f, x0,A,b,Aeq,beq,lb,ub,nlc,options) +disp(xopt,fopt,exitflag,output,lambda,gradient,hessian) +disp("2nd") +[xopt,fopt,exitflag,output,lambda,gradient,hessian] =fmincon(f, x0,A,b,Aeq,beq,lb,ub,nlc) +disp(xopt,fopt,exitflag,output,lambda,gradient,hessian) diff --git a/tests/general_tests/fmincon/fmincon_logical12.sce b/tests/general_tests/fmincon/fmincon_logical12.sce new file mode 100644 index 0000000..325cd2c --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical12.sce @@ -0,0 +1,14 @@ + // 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 +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,[]) diff --git a/tests/general_tests/fmincon/fmincon_logical13.sce b/tests/general_tests/fmincon/fmincon_logical13.sce new file mode 100644 index 0000000..3c6b87d --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical13.sce @@ -0,0 +1,19 @@ +// Example with objective function and inequality constraints + +function y=fun(x) + y=0 + for i = 1:20 + y = y + exp(x(i)) + end +endfunction + +x0 = repmat(1,1,20); +lb = repmat(0,1,20); + +//Nonlinear constraints +function [c,ceq]=nlc(x) +c = [- 0.5*exp(x(1)) - 2.5*exp(x(2)) - 1.5*exp(x(3)) + 50]; +ceq = []; +endfunction + +[xopt,fopt,exitflag,output,lambda,gradient,hessian] = fmincon (fun, x0,[],[],[],[],lb,[],nlc) diff --git a/tests/general_tests/fmincon/fmincon_logical14.sce b/tests/general_tests/fmincon/fmincon_logical14.sce new file mode 100644 index 0000000..2febc72 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_logical14.sce @@ -0,0 +1,26 @@ +// Example with objective function and inequality constraints + +function y=fun(x) + y=0 + for i = 1:20 + y = y + exp(x(i)) + end +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) + cfor = 0; + for i = 1:20 + cfor = cfor + 2*exp(x(i)) + end + c = [ cfor + 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_logical4.sce b/tests/general_tests/fmincon/fmincon_logical4.sce index 31221c8..09b2b36 100644 --- a/tests/general_tests/fmincon/fmincon_logical4.sce +++ b/tests/general_tests/fmincon/fmincon_logical4.sce @@ -13,7 +13,7 @@ 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]; +c = [x(1)^2 - x(2)^2 + 0.5 ; x(1)^2 + x(2)^2 - 2.5]; ceq = []; endfunction diff --git a/tests/general_tests/fmincon/fmincon_logical7.sce b/tests/general_tests/fmincon/fmincon_logical7.sce index 48d83b4..36c6ae3 100644 --- a/tests/general_tests/fmincon/fmincon_logical7.sce +++ b/tests/general_tests/fmincon/fmincon_logical7.sce @@ -1,7 +1,7 @@ // Example with objective function using exponential input function y=fun(x) -y=exp(x(2)*x(1)); + y=exp(x(2)*x(1)); endfunction x0 = [1,2]; diff --git a/tests/general_tests/lsqnonlin/lsqnonlin_A1.sce b/tests/general_tests/lsqnonlin/lsqnonlin_A1.sce new file mode 100644 index 0000000..1c2128b --- /dev/null +++ b/tests/general_tests/lsqnonlin/lsqnonlin_A1.sce @@ -0,0 +1,19 @@ +// 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_logical1.sce b/tests/general_tests/lsqnonlin/lsqnonlin_logical1.sce new file mode 100644 index 0000000..aef546f --- /dev/null +++ b/tests/general_tests/lsqnonlin/lsqnonlin_logical1.sce @@ -0,0 +1,7 @@ +function retF = testmyfun(x) + km = [1:10]'; + retF = 2 + 2*km-exp(km*x(1))-exp(km*x(2)); +endfunction + +x0 = [0.3 0.4]' +[x,resnorm] = lsqnonlin(testmyfun,x0) |