Matlab curve fitting toolbox acting weird
이전 댓글 표시
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
Walter Roberson
2019년 10월 3일
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
2019년 10월 4일
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
2019년 10월 4일
Haneya Qureshi
2019년 10월 4일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!