how can we plot our 4th order polynomial with given data by using polyfit and polyval ?

22 Ansichten (letzte 30 Tage)
x=[0.1 0.2 0.4 0.6 0.9 1.3 1.5 1.7 1.8];
y=[0.75 1.25 1.45 1.25 0.85 0.55 0.35 0.28 0.18];
n=9;
figure
pfit4=polyfit(x,y,4);
plot(x,y,'ro')
hold on
grid on
plot(x,pfit4,'g-')
hold off
title('polyfit table')
figure
pval4=polyval(x,y,4);
plot(x,y,'ro')
hold on
grid on
plot(x,pval4,'g-')
hold off
title('polyval table')

Antworten (1)

Star Strider
Star Strider am 6 Mai 2019
You have the correct idea, and correct code except for the polyval call.
Try this:
x=[0.1 0.2 0.4 0.6 0.9 1.3 1.5 1.7 1.8];
y=[0.75 1.25 1.45 1.25 0.85 0.55 0.35 0.28 0.18];
pfit4=polyfit(x,y,4);
pval4=polyval(pfit4,x,4);
figure
plot(x,y,'ro')
hold on
plot(x,pval4,'g-')
hold off
title('polyval table')
That should do what you want:
how can we plot our 4th order polynomial with given data by using polyfit and polyval - 2019 05 06.png

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by