Global curve fitting for polynomial function
Ältere Kommentare anzeigen
Hello all,
I have two sets of data (xdata1, ydata1, and xdata2, ydata2) and I would like to do a global curve fit for these. The function is:
y = y0 + ax + bx^2 + cx^3
where y0 is a shared parameter and a, b, and c can vary for each data set.
I am quite new to MATLAB so I am wondering if anyone have a clue of how to do this?
Thank you in advance for any answers.
/Christian
Antworten (3)
dbmn
am 10 Okt. 2016
p = polyfit(xdata1,ydata1,3);
3 Kommentare
I just read, that the y0 should be shared. For forcing the curve trough a specific point y_offset @x==0 you can use the following
params = [x'.^3, x'.^2, x']\(y-y_offset)';
c = params(1); b = params(2); a = params(3);
You might need of not need the ' depending on the shape of your x and y vectors.
[edit: credit to John d'Errico for the solution with the Solution with the mldivide operator]
Torsten
am 10 Okt. 2016
y_offset is also an unknown parameter.
Best wishes
Torsten.
Christian Sögaard
am 10 Okt. 2016
Bearbeitet: Christian Sögaard
am 10 Okt. 2016
Torsten
am 10 Okt. 2016
The objective function for your problem is given by
f(y0,a1,b1,c1,a2,b2,c2)=
sum_{i=1}^{n1}(ydata1_{i}-(y0+a1*xdata1_{i}+b1*xdata1_{i}^2+c1*xdata1_{i}^3))^2 +
sum_{i=1}^{n2}(ydata2_{i}-(y0+a2*xdata2_{i}+b2*xdata2_{i}^2+c2*xdata2_{i}^3))^2
Now take partial derivatives of f with respect to y0,a1,b1,c1,a2,b2,c2.
You'll arrive at a (7x7) linear system of equations in the unknows y0,a1,b1,c1,a2,b2,c2. This can be solved using \ (backslash).
Best wishes
Torsten.
2 Kommentare
Alternativly, solve the (overdetermined) linear system of equations using \ (backslash):
y0+a1*xdata1_{i}+b1*xdata1_{i}^2+c1*xdata1_{i}^3=ydata1_{i} (i=1,...,n1)
y0+a2*xdata2_{i}+b2*xdata2_{i}^2+c2*xdata2_{i}^3=ydata2_{i} (i=1,...,n2)
These are (n1+n2) equations in the unknowns y0,a1,a2,a3,b1,b2,b3.
Best wishes
Torsten.
Christian Sögaard
am 14 Okt. 2016
Christian Sögaard
am 14 Okt. 2016
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!