summaryrefslogtreecommitdiff
path: root/tests/general_tests/lsqnonlin
diff options
context:
space:
mode:
authorharpreet2016-04-16 12:12:15 +0530
committerharpreet2016-04-16 12:12:15 +0530
commit10e2e4d8b4a7592a8631ddac8e8d1664d6f0b9e3 (patch)
tree087af3ca1853d01afef58684b09b537597317023 /tests/general_tests/lsqnonlin
parent8484c85784b84cc3a9257f8d8065b3a8a7800628 (diff)
downloadFOSSEE-Optimization-toolbox-10e2e4d8b4a7592a8631ddac8e8d1664d6f0b9e3.tar.gz
FOSSEE-Optimization-toolbox-10e2e4d8b4a7592a8631ddac8e8d1664d6f0b9e3.tar.bz2
FOSSEE-Optimization-toolbox-10e2e4d8b4a7592a8631ddac8e8d1664d6f0b9e3.zip
fmincon examples
Diffstat (limited to 'tests/general_tests/lsqnonlin')
-rw-r--r--tests/general_tests/lsqnonlin/lsqnonlin_A1.sce19
-rw-r--r--tests/general_tests/lsqnonlin/lsqnonlin_input1.sce29
-rw-r--r--tests/general_tests/lsqnonlin/lsqnonlin_input2.sce29
-rw-r--r--tests/general_tests/lsqnonlin/lsqnonlin_lb1.sce32
-rw-r--r--tests/general_tests/lsqnonlin/lsqnonlin_lb2.sce32
-rw-r--r--tests/general_tests/lsqnonlin/lsqnonlin_lbub.sce32
-rw-r--r--tests/general_tests/lsqnonlin/lsqnonlin_logical1.sce11
-rw-r--r--tests/general_tests/lsqnonlin/lsqnonlin_maxiter.sce65
-rw-r--r--tests/general_tests/lsqnonlin/lsqnonlin_param1.sce32
-rw-r--r--tests/general_tests/lsqnonlin/lsqnonlin_param2.sce31
-rw-r--r--tests/general_tests/lsqnonlin/lsqnonlin_ub1.sce32
-rw-r--r--tests/general_tests/lsqnonlin/lsqnonlin_ub2.sce32
-rw-r--r--tests/general_tests/lsqnonlin/lsqnonlin_x01.sce29
-rw-r--r--tests/general_tests/lsqnonlin/lsqnonlin_x02.sce29
14 files changed, 411 insertions, 23 deletions
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)