summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHarpreet2016-03-03 08:59:34 +0530
committerHarpreet2016-03-03 08:59:34 +0530
commit7cf9300c2eb4773afa9823cf4a179d43f70001aa (patch)
tree62f03c9c2df9ffe1c061d346a2059cc0fe862ba0 /tests
parentd0cad398d8df199a4974112bfb7945c18636b5f8 (diff)
downloadFOSSEE-Optimization-toolbox-7cf9300c2eb4773afa9823cf4a179d43f70001aa.tar.gz
FOSSEE-Optimization-toolbox-7cf9300c2eb4773afa9823cf4a179d43f70001aa.tar.bz2
FOSSEE-Optimization-toolbox-7cf9300c2eb4773afa9823cf4a179d43f70001aa.zip
lsqnonlin added
Diffstat (limited to 'tests')
-rw-r--r--tests/general_tests/fmincon/fmincon_grad1.sce44
-rw-r--r--tests/general_tests/fmincon/fmincon_grad2.sce44
-rw-r--r--tests/general_tests/fmincon/fmincon_gradcon1.sce44
-rw-r--r--tests/general_tests/fmincon/fmincon_gradcon2.sce44
-rw-r--r--tests/general_tests/fmincon/fmincon_gradcon3.sce44
-rw-r--r--tests/general_tests/fmincon/fmincon_hess1.sce44
-rw-r--r--tests/general_tests/fmincon/fmincon_hess2.sce44
-rw-r--r--tests/general_tests/fmincon/fmincon_nlc1.sce44
-rw-r--r--tests/general_tests/fmincon/fmincon_nlc2.sce44
-rw-r--r--tests/general_tests/fmincon/fmincon_nlc3.sce44
-rw-r--r--tests/general_tests/fmincon/fmincon_nlc4.sce40
-rw-r--r--tests/general_tests/fmincon/fmincon_options1.sce44
-rw-r--r--tests/general_tests/fmincon/fmincon_options2.sce44
-rw-r--r--tests/unit_tests/lsqnonlin.dia.ref83
-rw-r--r--tests/unit_tests/lsqnonlin.tst83
15 files changed, 734 insertions, 0 deletions
diff --git a/tests/general_tests/fmincon/fmincon_grad1.sce b/tests/general_tests/fmincon/fmincon_grad1.sce
new file mode 100644
index 0000000..bf72b8f
--- /dev/null
+++ b/tests/general_tests/fmincon/fmincon_grad1.sce
@@ -0,0 +1,44 @@
+
+//Incompatibility between user defined gradient function and dimensions of the starting point x0
+
+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: Gradient function of Objective and x0 did not match
+//at line 606 of function fmincon called by :
+//fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options)
+//at line 44 of exec file called by :
+//exec fmincon_grad1.sce
+
+function [c,ceq]=nlc(x)
+ c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1];
+ ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75];
+endfunction
+
+//x(4) is invalid here
+function y= fGrad(x)
+ y= [x(2),x(1)+x(3),x(4)];
+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)
diff --git a/tests/general_tests/fmincon/fmincon_grad2.sce b/tests/general_tests/fmincon/fmincon_grad2.sce
new file mode 100644
index 0000000..9f29a39
--- /dev/null
+++ b/tests/general_tests/fmincon/fmincon_grad2.sce
@@ -0,0 +1,44 @@
+
+//User defined gradient function does not return a vector
+
+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: Wrong Input for Objective Gradient function(10th Parameter)---->Vector function is Expected
+//at line 615 of function fmincon called by :
+//fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options)
+//at line 44 of exec file called by :
+//exec fmincon_grad2.sce
+
+function [c,ceq]=nlc(x)
+ c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1];
+ ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75];
+endfunction
+
+function y= fGrad(x)
+ //y is not a vector here
+ y= [x(2),x(1)+x(3);x(2),x(1)];
+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)
diff --git a/tests/general_tests/fmincon/fmincon_gradcon1.sce b/tests/general_tests/fmincon/fmincon_gradcon1.sce
new file mode 100644
index 0000000..7a1efa4
--- /dev/null
+++ b/tests/general_tests/fmincon/fmincon_gradcon1.sce
@@ -0,0 +1,44 @@
+
+//Incompatibility between user defined constraint gradient function and dimensions of the starting point x0
+
+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: Gradient function of Constraint and x0 did not match
+//at line 640 of function fmincon called by :
+//fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options)
+//at line 44 of exec file called by :
+//exec fmincon_gradcon1.sce
+
+function [c,ceq]=nlc(x)
+ c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1];
+ ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75];
+endfunction
+
+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
+
+//x(4) is invalid here
+function [cg,ceqg] = cGrad(x)
+ cg = [2*x(1),0,0;2*x(1),2*x(2),0;0,0,2*x(4)];
+ ceqg = [3*x(1)^2,0,0;0,2*x(2),2*x(4)];
+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)
diff --git a/tests/general_tests/fmincon/fmincon_gradcon2.sce b/tests/general_tests/fmincon/fmincon_gradcon2.sce
new file mode 100644
index 0000000..f064e98
--- /dev/null
+++ b/tests/general_tests/fmincon/fmincon_gradcon2.sce
@@ -0,0 +1,44 @@
+
+//Wrong dimensions of non-linear inequality constraint gradient function
+
+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: Definition of (cg) in Non-Linear Constraint function(10th Parameter) should be in the form of (m X n) or Empty Matrix where m is number of Non- linear inequality constraints and n is number of Variables
+//at line 647 of function fmincon called by :
+//ncon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options
+//at line 44 of exec file called by :
+//exec fmincon_gradcon2.sce
+
+function [c,ceq]=nlc(x)
+ c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1];
+ ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75];
+endfunction
+
+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
+
+//Dimension of cg is wrong here
+function [cg,ceqg] = cGrad(x)
+ cg = [2*x(1),0,0;2*x(1),2*x(2),0;0,0,2*x(3);1,0,1];
+ 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)
diff --git a/tests/general_tests/fmincon/fmincon_gradcon3.sce b/tests/general_tests/fmincon/fmincon_gradcon3.sce
new file mode 100644
index 0000000..eeda192
--- /dev/null
+++ b/tests/general_tests/fmincon/fmincon_gradcon3.sce
@@ -0,0 +1,44 @@
+
+//Wrong dimensions of non-linear equality constraint gradient function
+
+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: Definition of (ceqg) in Non-Linear Constraint function(10th Parameter) should be in the form of (m X n) or Empty Matrix where m is number of Non- linear equality constraints and n is number of Variables
+//at line 653 of function fmincon called by :
+//fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options)
+//at line 44 of exec file called by :
+//exec fmincon_gradcon3.sce
+
+function [c,ceq]=nlc(x)
+ c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1];
+ ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75];
+endfunction
+
+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
+
+//Dimension of ceqg is wrong here
+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,x(3);0,2*x(2),2*x(3),2*x(1)];
+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)
diff --git a/tests/general_tests/fmincon/fmincon_hess1.sce b/tests/general_tests/fmincon/fmincon_hess1.sce
new file mode 100644
index 0000000..058f521
--- /dev/null
+++ b/tests/general_tests/fmincon/fmincon_hess1.sce
@@ -0,0 +1,44 @@
+
+//Incompatibility between user defined hessian function and dimensions of the starting point x0
+
+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: Hessian function of Objective and x0 did not match
+//at line 625 of function fmincon called by :
+//fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options)
+//at line 44 of exec file called by :
+//exec fmincon_hess1.sce
+
+function [c,ceq]=nlc(x)
+ c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1];
+ ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75];
+endfunction
+
+function y= fGrad(x)
+ y= [x(2),x(1)+x(3),x(2)];
+endfunction
+
+//x(4) is invalid here
+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(4),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)
diff --git a/tests/general_tests/fmincon/fmincon_hess2.sce b/tests/general_tests/fmincon/fmincon_hess2.sce
new file mode 100644
index 0000000..58f8804
--- /dev/null
+++ b/tests/general_tests/fmincon/fmincon_hess2.sce
@@ -0,0 +1,44 @@
+
+//User defined hessian is of wrong dimensions
+
+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: Wrong Input for Objective Hessian function(10th Parameter)---->Symmetric Matrix function is Expected
+//at line 630 of function fmincon called by :
+//fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options)
+//at line 44 of exec file called by :
+//exec fmincon_hess2.sce
+
+function [c,ceq]=nlc(x)
+ c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1];
+ ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75];
+endfunction
+
+function y= fGrad(x)
+ y= [x(2),x(1)+x(3),x(2)];
+endfunction
+
+//Wrong dimensions of Hessian here
+function y= lHess(x,obj,lambda)
+ y= obj*[0,1;1,0;0,1] + lambda(1)*[2,0;0,0;0,0] + lambda(2)*[2,0;0,2;0,0] +lambda(3)*[0,0;0,0;0,0] + lambda(4)*[6*x(1),0;0,0;0,0] + lambda(5)*[0,0;0,2;0,0];
+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)
diff --git a/tests/general_tests/fmincon/fmincon_nlc1.sce b/tests/general_tests/fmincon/fmincon_nlc1.sce
new file mode 100644
index 0000000..65064d7
--- /dev/null
+++ b/tests/general_tests/fmincon/fmincon_nlc1.sce
@@ -0,0 +1,44 @@
+
+//Mismatch in dimensions of starting point x0 and that of non-linear constraints
+
+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 function(9th Parameter) and x0(2nd Parameter) did not match
+//at line 487 of function fmincon called by :
+//fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options)
+//at line 44 of exec file called by :
+//exec fmincon_nlc1.sce
+
+function [c,ceq]=nlc(x)
+ //x(4) is out of dimension here when compared to x0
+ c=[x(1)^2-1,x(4)^2+x(2)^2-1,x(4)^2-1];
+ ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75];
+endfunction
+
+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)
diff --git a/tests/general_tests/fmincon/fmincon_nlc2.sce b/tests/general_tests/fmincon/fmincon_nlc2.sce
new file mode 100644
index 0000000..5a524fd
--- /dev/null
+++ b/tests/general_tests/fmincon/fmincon_nlc2.sce
@@ -0,0 +1,44 @@
+
+//Checking if non-linear inequality constraints are specified in row vector format
+
+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: Definition of c in Non-Linear Constraint function(9th Parameter) should be in the form of Row Vector or Empty Vector
+//at line 493 of function fmincon called by :
+//fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options)
+//at line 44 of exec file called by :
+//exec fmincon_nlc2.sce
+
+function [c,ceq]=nlc(x)
+ //Expected a row vector or an empty vector for c, but found a column vector
+ c=[x(1)^2-1;x(1)^2+x(2)^2-1;x(3)^2-1];
+ ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75];
+endfunction
+
+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)
diff --git a/tests/general_tests/fmincon/fmincon_nlc3.sce b/tests/general_tests/fmincon/fmincon_nlc3.sce
new file mode 100644
index 0000000..d82bf84
--- /dev/null
+++ b/tests/general_tests/fmincon/fmincon_nlc3.sce
@@ -0,0 +1,44 @@
+
+//Checking if non-linear equality constraints are specified in row vector format
+
+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: Definition of ceq in Non-Linear Constraint function(9th Parameter) should be in the form of Row Vector or Empty Vector
+//at line 498 of function fmincon called by :
+//fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options)
+//at line 44 of exec file called by :
+//exec fmincon_nlc3.sce
+
+function [c,ceq]=nlc(x)
+ c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1];
+ //Expected a row vector or an empty vector for ceq, but found a column vector
+ ceq=[x(1)^3-0.5;x(2)^2+x(3)^2-0.75];
+endfunction
+
+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)
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)
diff --git a/tests/general_tests/fmincon/fmincon_options1.sce b/tests/general_tests/fmincon/fmincon_options1.sce
new file mode 100644
index 0000000..e5fc008
--- /dev/null
+++ b/tests/general_tests/fmincon/fmincon_options1.sce
@@ -0,0 +1,44 @@
+
+//Size of options is not even
+
+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: Size of Options (list) should be even
+//at line 558 of function fmincon called by :
+//fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options)
+//at line 43 of exec file called by :
+//exec fmincon_options1.sce
+
+function [c,ceq]=nlc(x)
+ c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1];
+ ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75];
+endfunction
+
+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
+
+//cGrad is missing in the options
+options=list("MaxIter", [1500], "CpuTime", [500], "GradObj", fGrad, "Hessian", lHess,"GradCon");
+
+[x,fval,exitflag,output,lambda,grad,hessian] =fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options)
diff --git a/tests/general_tests/fmincon/fmincon_options2.sce b/tests/general_tests/fmincon/fmincon_options2.sce
new file mode 100644
index 0000000..1097690
--- /dev/null
+++ b/tests/general_tests/fmincon/fmincon_options2.sce
@@ -0,0 +1,44 @@
+
+//Typing error in arguments to options
+
+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: Unrecognized parameter name GradientObj.
+//at line 596 of function fmincon called by :
+//fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options)
+//at line 44 of exec file called by :
+//exec fmincon_options2.sce
+
+function [c,ceq]=nlc(x)
+ c=[x(1)^2-1,x(1)^2+x(2)^2-1,x(3)^2-1];
+ ceq=[x(1)^3-0.5,x(2)^2+x(3)^2-0.75];
+endfunction
+
+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
+
+//Typing error: Expected "GradObj" instead of "GradientObj"
+options=list("MaxIter", [1500], "CpuTime", [500], "GradientObj", fGrad, "Hessian", lHess,"GradCon",cGrad);
+
+[x,fval,exitflag,output,lambda,grad,hessian] =fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlc,options)
diff --git a/tests/unit_tests/lsqnonlin.dia.ref b/tests/unit_tests/lsqnonlin.dia.ref
new file mode 100644
index 0000000..916d9dc
--- /dev/null
+++ b/tests/unit_tests/lsqnonlin.dia.ref
@@ -0,0 +1,83 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: Harpreet Singh
+// Organization: FOSSEE, IIT Bombay
+// Email: harpreet.mertia@gmail.com
+//
+// 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
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+
+//
+// assert_close --
+// Returns 1 if the two real matrices computed and expected are close,
+// i.e. if the relative distance between computed and expected is lesser than epsilon.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+function flag = assert_close ( computed, expected, epsilon )
+ if expected==0.0 then
+ shift = norm(computed-expected);
+ else
+ shift = norm(computed-expected)/norm(expected);
+ end
+// if shift < epsilon then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+ flag = assert_checktrue ( shift < epsilon );
+endfunction
+//
+// assert_equal --
+// Returns 1 if the two real matrices computed and expected are equal.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+//function flag = assert_equal ( computed , expected )
+// if computed==expected then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+//endfunction
+
+//A simple non-linear least square example taken from leastsq default present in scilab
+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
+// the simplest call
+[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0)
+
+assert_close ( xopt , [ 0.9940629 0.9904811 ]' , 0.0005 );
+assert_close ( residual , [-0.0139785 0.0158061 0.0029263 0.0091929 -0.0017872 -0.0050049 0.0056439 -0.0128825 -0.0129584 0.0035627]' , 0.0005 );
+assert_close ( resnorm , [ 0.0009450] , 0.0005 );
+assert_checkequal( exitflag , int32(0) );
+printf("Test Successful");
diff --git a/tests/unit_tests/lsqnonlin.tst b/tests/unit_tests/lsqnonlin.tst
new file mode 100644
index 0000000..916d9dc
--- /dev/null
+++ b/tests/unit_tests/lsqnonlin.tst
@@ -0,0 +1,83 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: Harpreet Singh
+// Organization: FOSSEE, IIT Bombay
+// Email: harpreet.mertia@gmail.com
+//
+// 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
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+
+//
+// assert_close --
+// Returns 1 if the two real matrices computed and expected are close,
+// i.e. if the relative distance between computed and expected is lesser than epsilon.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+function flag = assert_close ( computed, expected, epsilon )
+ if expected==0.0 then
+ shift = norm(computed-expected);
+ else
+ shift = norm(computed-expected)/norm(expected);
+ end
+// if shift < epsilon then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+ flag = assert_checktrue ( shift < epsilon );
+endfunction
+//
+// assert_equal --
+// Returns 1 if the two real matrices computed and expected are equal.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+//function flag = assert_equal ( computed , expected )
+// if computed==expected then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+//endfunction
+
+//A simple non-linear least square example taken from leastsq default present in scilab
+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
+// the simplest call
+[xopt,resnorm,residual,exitflag,output,lambda,gradient] = lsqnonlin(myfun,x0)
+
+assert_close ( xopt , [ 0.9940629 0.9904811 ]' , 0.0005 );
+assert_close ( residual , [-0.0139785 0.0158061 0.0029263 0.0091929 -0.0017872 -0.0050049 0.0056439 -0.0128825 -0.0129584 0.0035627]' , 0.0005 );
+assert_close ( resnorm , [ 0.0009450] , 0.0005 );
+assert_checkequal( exitflag , int32(0) );
+printf("Test Successful");