Curve Fitting Toolbox: 1. Why using this mentioned curve equation, I am not getting back the same curve or can't get nearby value for in between points? 2. How matlab calculates f(xi), may be I that can also useful to me?

1 view (last 30 days)
For my experimental data points on x-axis [300.00 310.00 320.00 330.00 340.00 350.00 360.00 370.00 380.00 390.00 400.00 410.00 420.00 430.00 440.00 450.00 460.00 470.00 480.00 490.00 500.00 510.00 520.00 530.00 540.00 550.00 560.00 570.00 580.00 590.00 600.00 610.00 620.00 630.00 640.00 650.00 660.00 670.00 680.00 690.00 700.00 710.00 720.00 730.00 740.00 750.00 760.00 770.00 780.00] and for Y-axis [0.00 0.00 0.00 0.00 0.00 0.01 0.02 0.02 0.03 0.04 0.05 0.06 0.07 0.07 0.08 0.09 0.10 0.10 0.11 0.12 0.12 0.13 0.13 0.14 0.15 0.15 0.15 0.16 0.16 0.17 0.17 0.17 0.17 0.17 0.16 0.15 0.15 0.15 0.14 0.14 0.12 0.10 0.08 0.06 0.05 0.03 0.02 0.01 0.02]. Later I plotted and tried to fit curve. So for 6th or 7th polynomial fit I got equation for 92-points (but here pasted 52 points bcaz for other points value is near zero) with coefficient: f=(-2.751e-024)*x^9 + 1.863e-020*x^8 + (-5.473e-017)*x^7 + 9.149e-014*x^6 + (-9.589e-011)*x^5 + 6.534e-008*x^4 + (-2.893e-005)*x^3 + 0.008026*x^2 + ( -1.264)*x + 85.95. Next when I used 'Analysis' and plotting value for function i.e. f(xi) and xi=300:10:780; plotted curve for x-values and f(xi); matching very well. So my Question is: 1. Why using this mentioned curve equation, I am not getting back the same curve or can't get nearby value for in between points? 2. How matlab calculates f(xi), may be I that can also useful to me?
  3 Comments
dhiraj
dhiraj on 14 Sep 2013
Thanks dpb. I got answer and found culprit was "NUMBER ROUNDING ERROR". If we can set data format of matlab to 16-bit then it solves problem. Here is the equation which shows best fit: 1.786411371332003*10^(-22)*X^9 - 8.491473334467727*10^(-19)*X^8 + -0.00000000000000774766640460499*X^7 + 0.00000000000139128455325279*X^6 + 0.000000001637256531363544*X^5 - 0.0000008245185819792657*X^4 + 0.0002729524733576362*X^3 - 0.05722055084942492*X^2 + 6.886283289019546*X - 362.2051862232332. Here is the program: p1=polyfit(x,y,9); syms X; A=[X^9 X^8 X^7 X^6 X^5 X^4 X^3 X^2 X^1 X^0];P=vpa(A*p1',16); % adjust to 16 as per precision
for i=1:49
f(i)=subs(P,x(i)); % substitute x values
end
plot(x,y)
hold on
plot(x,f)
dpb
dpb on 15 Sep 2013
I have no idea what you're after above -- why not standardize and just use polyval() directly to get the better numerics?

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!