Estimate best parameters using lscurvefit

4 visualizzazioni (ultimi 30 giorni)
Oscar Nordin
Oscar Nordin il 26 Mag 2020
Modificato: John D'Errico il 27 Mag 2020
Given two datasets x and y. I have a very complicated function f depending on x, y and 3 parameters a=(a1,a2,a3) and want to find the parameters a that minimizes f.
For example lets say i have:
x=[1,2,3,4,5]
y=[1,3,5,7,9]
= +
where is a very complicated function of both a and x and is a complicated function of only a.
With fminsearch, the min value of f could be found by just creating a function of everything
fun = @(X)func(X);
where func is and then use
x0=fminsearch(fun,b)
where b = [b1, b2, b3] is an initial guess
But how can i do it with lscurvefit where i need to state x-data and y-data in the arguments?

Risposte (1)

John D'Errico
John D'Errico il 27 Mag 2020
Modificato: John D'Errico il 27 Mag 2020
You are getting lost and confused by the names x and y. They are irrelevant. You have 3 parameters. You have 5 data points, numbered here from 1 to 5. lsqcurvefit does not really care about x and y as such.
Your target here is apparently zero for each such data point.
Just create an objective that evaluates the 5 results, and then returns then to lsqcurvefit, AS A FUNCTION of the parameters.
As easily, you could just use lsqnonlin, since your target is zero anyway for all 5 "data points". Just return the vector f_a.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by