Fitting a curve to 5th degree polynomial
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I need to fit a curve to 5th degree polynomial. I am able to do the same using Basic fitting tool. But I need to write the code for the same. I looked 'polyfit' and obtained the coefficients but I need a code to plot the curve obtained after fitting.
0 comentarios
Respuestas (1)
Walter Roberson
el 29 de Jul. de 2015
pp = polyfit(x, y, 5);
plot(x, polyval(pp, x))
2 comentarios
Torsten
el 29 de Jul. de 2015
I think one will have to choose a finer grid than the x-vector in order to see how the polynomial behaves between the given interpolation points.
Maybe
pp = polyfit(x, y, 5);
xx=linspace(x(1),x(end),10*length(x));
figure
plot(x,y,'o')
hold on
plot(xx,polyval(pp,xx))
hold off
Best wishes
Torsten.
Walter Roberson
el 29 de Jul. de 2015
a 5th degree polynomial is going to be smooth over the range of the provided x values, so refining before plotting is not going to show anything of interest, likely. The difficulties are going to come past the ends of the defined range; interpolation with polynomials becomes increasingly problematic as the degree of the polynomial increases.
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!