Matlab curve fitting toolbox acting weird
Afficher commentaires plus anciens
I am entering v as x variable and G as y variable in matlab toolbox and fitting it using sum of sines, no. of terms =2
v=-90:90;
B=65;
G=(v./B).^2;
I am getting output shown below. This shows a great fit. But when I write the equation using coefficients given by matlab myself, the graph I get is not the same!!!
fitresult(x) = a1*sin(b1*x+c1) + a2*sin(b2*x+c2)
Coefficients (with 95% confidence bounds):
a1 = 504.9 (-6.058e+08, 6.058e+08)
b1 = 0.01277 (-26.03, 26.06)
c1 = 1.571 (1.525, 1.617)
a2 = 505 (-6.058e+08, 6.058e+08)
b2 = 0.01281 (-25.95, 25.98)
c2 = -1.571 (-1.617, -1.525)
4 commentaires
Walter Roberson
le 3 Oct 2019
Any time you see fitting coefficient bounds that cross 0 and are roughly the same positive and negative, then you should understand that the curve fitting toolbox was unable to decide on the appropriate sign of the coefficient.
Your two sub-expressions are symmetric to each other, so MATLAB cannot decide between A*sin(B*x+C) + D*sin(E*x+F) compared to D*sin(E*x+F)+A*sin(B*x+C) and therefore the 95% confidence bounds will be of little value, reflecting the full range for both coefficients. Likewise, because sin(-x) = -sin(x), then A*sin(B*x+C) = (-A)*sin((-B)*x+(-C)) and so curve fitting cannot decide between the signs of the terms.
You should be adding in constraints to make the coefficient order unique. For example you can pin down a1 and a2 to be positive while letting b1, b2 be positive or negative, and you can pin down c1 and c2 to be in the range +/- pi . You would also prefer to make a1 <= a2
Walter Roberson
le 4 Oct 2019
But when I write the equation using coefficients given by matlab myself
How are you doing that? Remember that you are only seeing about 4 decimal places. You would want to use coeffvalues(fitresult) to get the full values.
Haneya Qureshi
le 4 Oct 2019
Haneya Qureshi
le 4 Oct 2019
Réponses (0)
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!