How to properly use fmincon and optimization?

7 vues (au cours des 30 derniers jours)
Nam Tran
Nam Tran le 7 Avr 2017
Hello All,
I have asked a question on this before but still can't seem to figure it out. So I will try my best to be more specific now. Essentially, I need help using Fmincon/lsqnonlin.
I have two sets of data. One created by a software (numerical simulation). Lets call the data (t,x)
The other set of data is created by a code in matlab. This code is quite hectic and complex. We can call this data set (t,z). There are 10+ imput parameters that have the same "range". Right now I have my matlab function set up as
min=f(k)
where k is the vector of parameters, and min is (z1-x1)^2+(z2-x2)^2...and so on.
I want to guess the parameters that minimizes the "min". I'm not sure if this is the correct way to go about it. I think one of the problem is that my parameters are very small value range of 10^-13 to 10^-15 or even smaller.
My function does not use the parameters as directly as ax+b=c where you can guess a and b for a line fit. There are a series of bessel functions involved. What i am trying to do is "match" datapoints and not necessarily a line fit.
I hope this make sense. I've been stuck on this problem for so long but I feel like the solution is so simple.

Réponses (2)

Alan Weiss
Alan Weiss le 7 Avr 2017
It sounds like lsqcurvefit is eminently suited to your problem, except for the scaling issue of too-small function values. I would multiply everything by 1e12 or so just to have a chance that the solver won't stop immediately, thinking that it found a point where the values are very close.
The documentation is reasonably clear, I hope. Here is an example. The idea is you have parameters that you can vary in a single vector, usually called x. You have your xdata, which I think you call t, meaning the values that you are examining, and you have the response values ydata in your output that you call x. The function you have gives you fun(t) = z values, and you want to minimize the difference between fun(t) and your x in terms of sum of squares.
So just set your fun, xdata, and ydata as I indicated, and give lsqcurvefit a try. If it stops too soon, try multiplying everything by 1e12, I mean both the ydata = x and the output of the function fun.
For another example, including how you might use fminunc or fmincon, see Nonlinear Data-Fitting.
Alan Weiss
MATLAB mathematical toolbox documentation

Walter Roberson
Walter Roberson le 7 Avr 2017
Unless you are able to use constraints to restrict yourself to a smooth region, it is unlikely that either routine would be useful to you. You probably need a global minimizer rather than a local minimizer. You should look at the global optimization toolbox

Community Treasure Hunt

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

Start Hunting!

Translated by