Function lsqnonlin() has no optimization effect

It is a teaching example, but I can't get the right answer in my software. How can I solve this problem?

4 Comments

Well, I tried the code, and it produce
x =
0.2578 0.2578
resnorm =
124.3622
also with the warning information as well
lsqnonlin stopped because the size of the current step is less than
the value of the step size tolerance.
Perhaps, we can ignore this warning.
Matt J
Matt J on 17 May 2020
Edited: Matt J on 17 May 2020
@Yuwen,
Please do not post your code as an embedded image. We cannot conveniently copy-paste it in that form.
@Ang Feng,
It is not a warning. It is an announcement of success! (Or at least, lsqnonlin believes that it was successful).
@Matt J@Ang Feng Thanks for your answers. I try this code again, and it works right.
And I have another question. My code has no optimization effection.
function f=objfunc(x)
PNO=[60.8,60.8,60.8,60.8,60.8,60.8,15.2,30.4,60.8,121.59,151.99,202.65,60.8,60.8,60.8,60.8,60.8];
PO2=[253.3,506.6,1013.3,2026.5,5066.3,10132.5,2026.5,2026.5,2026.5,2026.5,2026.5,2026.5,2026.5,2026.5,2026.5,2026.5,2026.5];
rNO=[7.12e-05,9.66e-05,1.31e-04,1.77e-04,2.66e-04,3.60e-04,5.32e-05,9.72e-06,1.77e-04,3.25e-04,3.948e-04,5.07e-04,1.79e-04,1.77e-04,1.79e-04,1.76e-04,1.79e-04];
a=log(PNO);
b=log(PO2);
y=log(rNO);
f=x(1)+a*x(2)+b*x(3)-y;
x0=[-16.800207,1.2008,0.4151];
[x,resnorm]=lsqnonlin(@objfunc,x0)
Local minimum found.
Optimization completed because the size of the gradient is less than
the value of the optimality tolerance.
<stopping criteria details>
x =
-16.8802 1.2008 0.4151
resnorm =
4.4249

Sign in to comment.

Answers (1)

And I have another question. My code has no optimization effect
In this case, your initial guess already is optimal. You can see this by solving for the optimum x analytically, which is possible in this case because your model is linear, and because you have no bound constraints:
a=log(PNO(:));
b=log(PO2(:));
y=log(rNO(:));
x=[ones(size(a)),a,b]\y(:)
x =
-16.8802
1.2008
0.4151

Tags

Asked:

on 17 May 2020

Answered:

on 18 May 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!