how to pass a constrain in lsqcurvefit?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Arun Kumar Bar
il 29 Dic 2018
Commentato: Arun Kumar Bar
il 1 Gen 2019
Hi;
For a data set (x, y), I am trying to fit a function , fun(m, x), where there are four independent parameters m1, m2, m3 and m4, with the condtion that m1>m2. Could anyone please suggest how could I pass this condition in the following?
x=xdata;
y=ydata;
fun=(m,x);
lb=[];
m0=[m01; m02; m03]
ub=[];
m=lsqcurvefit(fun, m0, xdata, ydata, lb, ub);
Thank you very much in advance!
Kind regards,
Arun
0 Commenti
Risposta accettata
John D'Errico
il 29 Dic 2018
You cannot impose a strict inequality constraint. In fact, as you have learned based on your other question, sometimes even the bounds can be exceeded by a small amount.
There are simple ways to fix this, for example, using a transformation. Thus you might do something like this in your objective function:
function z = fun(m,x)
mt = m;
mt(2) = m(1) + exp(m(2));
...
Now there are no questions about an inequality. You will need to supply intelligent starting values for the initial m. And when lsqcurvefit returns a result, you must transform it the same way to have the parameters in your desired form. Or, you might use a transformation like
mt(2) = m(1) + m(2)^2;
Alternatively, you can use tools like fmincon to impose an inequality constraint. But remember that fmincon also does not understand a STRICT inequality of the form m(1)>m(2), and it too can exhibit constraint violations on the order of TolCon.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with Curve Fitting Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!