diff options
Diffstat (limited to 'tests/general_tests/fmincon/fmincon_nlc4.sce')
-rw-r--r-- | tests/general_tests/fmincon/fmincon_nlc4.sce | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/general_tests/fmincon/fmincon_nlc4.sce b/tests/general_tests/fmincon/fmincon_nlc4.sce new file mode 100644 index 0000000..7e7c180 --- /dev/null +++ b/tests/general_tests/fmincon/fmincon_nlc4.sce @@ -0,0 +1,40 @@ + +//If non-linear constraints is neither a function nor an empty matrix then flag an error + +function y=f(x) + y=x(1)*x(2)+x(2)*x(3); +endfunction + +x0=[1,1,1]; +A=[]; +b=[]; +Aeq=[]; +beq=[]; +lb=[0 0.2,-%inf]; +ub=[0.6 %inf,1]; + +//Error +//fmincon: Non Linear Constraint (9th Parameter) should be a function or an Empty Matrix +//at line 542 of function fmincon called by : +//fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options) +//at line 40 of exec file called by : +//exec fmincon_nlc4.sce + +nlc=[1,2,3,4]; + +function y= fGrad(x) + y= [x(2),x(1)+x(3),x(2)]; +endfunction + +function y= lHess(x,obj,lambda) + y= obj*[0,1,0;1,0,1;0,1,0] + lambda(1)*[2,0,0;0,0,0;0,0,0] + lambda(2)*[2,0,0;0,2,0;0,0,0] +lambda(3)*[0,0,0;0,0,0;0,0,2] + lambda(4)*[6*x(1 ),0,0;0,0,0;0,0,0] + lambda(5)*[0,0,0;0,2,0;0,0,2]; +endfunction + +function [cg,ceqg] = cGrad(x) + cg = [2*x(1),0,0;2*x(1),2*x(2),0;0,0,2*x(3)]; + ceqg = [3*x(1)^2,0,0;0,2*x(2),2*x(3)]; +endfunction + +options=list("MaxIter", [1500], "CpuTime", [500], "GradObj", fGrad, "Hessian", lHess,"GradCon", cGrad); + +[x,fval,exitflag,output,lambda,grad,hessian] =fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options) |