problems in passing parameters to fminsearchbnd.

1 view (last 30 days)
pietro on 27 Mar 2015
Commented: pietro on 28 Mar 2015
Hi all,
I have to fit some data and I'm using fminsearchbnd. Unfortunately the solver doesn't convergence and I have discovered that at the first iteration the design variable of myfunFitting function are different than the one supplied through the starting point. How may it be possible? Below you can find my code.
Thank you
x1=[76.2; 766.0; 842.5; 842.5; 1044.0; 1044.0; 1070.3; 987.0; ...
y2=[1845.697674; 2255;1845.697674;2255;1845.697674;2255;1845.697674;...
Target=[18196;13906;8209;6274;1913;1462;1444;1900;3054;2334;1377;1053;732;963;1444; ...
lb=[1 0];
ub=[1e40 20];
[xout fval,exitflag]=fminsearchbnd(f,x0a,lba,uba)
pietro on 27 Mar 2015
Edited: pietro on 27 Mar 2015
Thanks for your kind replies.
there were few mistakes in the code and I fixed them. exp and a are two flag variables and they can be deleted in the part of included code .
The design variables are scaled so both of them ranges from 0 to 1. For this reason I pass the bounds arrays inside the objective function.
Here the objective function:
function f=myfunFitting(xa,Target,x1,x2,lb,ub)

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 27 Mar 2015
So now we know why it is that your optimization is not working well. Here is your objective function.
function f=myfunFitting(xa,Target,x1,x2,lb,ub)
So you are trying to fit a model of the form
z = A/(B*y*x^B)
Where A and B are unknowns, and x and y are the independent variables.
Claim 1: Models with a single term that are the product of multiple variables like this almost ALWAYS need to be logged. The estimation is always easier, in fact, often trivial.
Claim 2: Whenever you have problems with huge orders of magnitudes involved, you should ALWAYS consider if you should be working with logs instead.
Lets see how that works here.
log(z) = log(A) - (log(B) + log(y) + B*log(x))
Rewrite this to look like...
log(z) + log(y) = log(A) - log(B) - B*log(x)
Now, think about it. Do you know the value of A? Do you know the value of B? Of course not. You are estimating them. So trivially, we can use the transformation
C = log(A) - log(B)
Putting it in a classic form...
log(z) - log(y) = C + B*(-log(x))
Use polyfit to determine B and C.
Here, we have x1 as x as I wrote it, y2 as y, and Target as z.
BC = polyfit(-log(x1),log(Target) + log(y2),1);
B = BC(1);
A = exp(BC(2) + log(B));
Sadly, I can't actually test this out on your data, because while you gave 24 elements in the vectors x1 and Target, there are only 15 in y2. The best that I can do is this:
BC = polyfit(-log(x1(1:15)),log(Target(1:15)) + log(y2),1)
BC =
0.61077 19.467
B = BC(1);
A = exp(BC(2) + log(B))
A =
That your data seems not to fit this model terribly well? Hey, it is your data and your choice of model.
Regardless, you should see that never did I need anything sophisticated to solve your problem. In fact, no serious optimization was ever needed. If you truly wanted to do an optimization, the above scheme would in the very least allow good starting values to be employed, but IF I actually wanted to do this as an optimization, the hugely wide bounds you have used would make that optimization totally unworkable even with the incredibly good starting values you will get from polyfit.
And finally, I would point out that had you defined exp as a variable in your workspace, the last line as I wrote it would now fail. Again, this is why that is a bad thing.
  1 Comment
pietro on 28 Mar 2015
Hi John,
Thanks for your reply, I did it as you suggested and it worked great. Just two question, is it fine how I have scaled the two variables? Why in my optimization at the first iteration the design variables are different than the starting point?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!