Prev: 3D Graph Or spectrogram
Next: qhull of a sphere
From: Robin on 21 May 2010 04:22 Hello, i try solving a problem with the matlab script "polyfit". It has the order 11. Polyfit calculates the polynom and his factos, if i plot the polynom with "polyval" the graph is correct, but if i try to write the poylnom as an equation it doesn´t work. p = 1.0e+011 *[ -0.0001 0.0015 -0.0146 0.0857 -0.3285 0.8606 -1.5659 1.9662 -1.6544 0.8761 -0.2567 0.0302] And x=2.8 y must be 114.9 with y = polyval(p,x) = 114.9 but y = 1.0e+011 *[-0.0001*x^11+0.0015*x^10-0.0146*x^9+0.0857*x^8-0.3285*x^7+0.8606*x^6-1.5659*x^5+1.9662*x^4-1.6544*x^3+0.8761*x^2-0.2567*x+0.0302] = -1.8419e+011 Any idea what´s the problem?
From: Matt J on 21 May 2010 06:28 "Robin " <robin.de.silva(a)iav.de> wrote in message <ht5frd$912$1(a)fred.mathworks.com>... > Hello, > > i try solving a problem with the matlab script "polyfit". It has the order 11. > > Polyfit calculates the polynom and his factos, if i plot the polynom with "polyval" the graph is correct, but if i try to write the poylnom as an equation it doesn´t work. > > p = 1.0e+011 *[ > -0.0001 0.0015 -0.0146 0.0857 -0.3285 0.8606 -1.5659 1.9662 -1.6544 0.8761 -0.2567 0.0302] > > And x=2.8 y must be 114.9 > > with y = polyval(p,x) = 114.9 > but y = 1.0e+011 *[-0.0001*x^11+0.0015*x^10-0.0146*x^9+0.0857*x^8-0.3285*x^7+0.8606*x^6-1.5659*x^5+1.9662*x^4-1.6544*x^3+0.8761*x^2-0.2567*x+0.0302] = -1.8419e+011 > > > > Any idea what´s the problem? Yes. The problem is you have copy/pasted all the coefficients directly from the screen, thinking that the values displayed on the screen by MATLAB are the exact ones. But this is not true. Don't you find it strange, for example, that MATLAB never displays a number with more than 4 decimal places?
From: John D'Errico on 21 May 2010 06:38 "Robin " <robin.de.silva(a)iav.de> wrote in message <ht5frd$912$1(a)fred.mathworks.com>... > Hello, > > i try solving a problem with the matlab script "polyfit". It has the order 11. > > Polyfit calculates the polynom and his factos, if i plot the polynom with "polyval" the graph is correct, but if i try to write the poylnom as an equation it doesn´t work. > > p = 1.0e+011 *[ > -0.0001 0.0015 -0.0146 0.0857 -0.3285 0.8606 -1.5659 1.9662 -1.6544 0.8761 -0.2567 0.0302] > > And x=2.8 y must be 114.9 > > with y = polyval(p,x) = 114.9 > but y = 1.0e+011 *[-0.0001*x^11+0.0015*x^10-0.0146*x^9+0.0857*x^8-0.3285*x^7+0.8606*x^6-1.5659*x^5+1.9662*x^4-1.6544*x^3+0.8761*x^2-0.2567*x+0.0302] = -1.8419e+011 > > > > Any idea what´s the problem? Congratulations. You win the award for the ten millionth person to discover floating point arithmetic, and the consequences thereof! (Sorry, but there is no monetary award offered.) http://docs.sun.com/source/806-3568/ncg_goldberg.html All of your computations are done in 16 digits of precision in matlab, so when you raise numbers to high powers, there are numerical problems. This is only ONE of the several reasons why you should NOT use high order polynomials. People easily seem to fall into this trap. They fit a linear polynomial with polyfit. It fits easily. So they try a quadratic, and the fit is improved. So they throw a cubic or higher order at their data, and the fit gets better. Eventually, they get greedy. Just keep on using a higher order polynomial. What could go wrong anyway? Yeah, right. Don't use high order polynomials. Instead, use a tool like my slm to fit a spline to your data. http://www.mathworks.com/matlabcentral/fileexchange/24443 John
From: Robin on 21 May 2010 06:38 "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <ht5n7l$4f1$1(a)fred.mathworks.com>... > "Robin " <robin.de.silva(a)iav.de> wrote in message <ht5frd$912$1(a)fred.mathworks.com>... > > Hello, > > > > i try solving a problem with the matlab script "polyfit". It has the order 11. > > > > Polyfit calculates the polynom and his factos, if i plot the polynom with "polyval" the graph is correct, but if i try to write the poylnom as an equation it doesn´t work. > > > > p = 1.0e+011 *[ > > -0.0001 0.0015 -0.0146 0.0857 -0.3285 0.8606 -1.5659 1.9662 -1.6544 0.8761 -0.2567 0.0302] > > > > And x=2.8 y must be 114.9 > > > > with y = polyval(p,x) = 114.9 > > but y = 1.0e+011 *[-0.0001*x^11+0.0015*x^10-0.0146*x^9+0.0857*x^8-0.3285*x^7+0.8606*x^6-1.5659*x^5+1.9662*x^4-1.6544*x^3+0.8761*x^2-0.2567*x+0.0302] = -1.8419e+011 > > > > > > > > Any idea what´s the problem? > > Yes. The problem is you have copy/pasted all the coefficients directly from the screen, thinking that the values displayed on the screen by MATLAB are the exact ones. > > But this is not true. Don't you find it strange, for example, that MATLAB never displays a number with more than 4 decimal places? Hello, thanks for the reply. After studying the coefficients i saw my mistake.
|
Pages: 1 Prev: 3D Graph Or spectrogram Next: qhull of a sphere |