matlab多項式曲線擬合polyfit(x,y,n)


x=[ -3 -1 0 2 5.5 7];
y=[3.3 4.5 2.0 1.5 2.5 -1.2];
p3=polyfit(x,y,3);
p4=polyfit(x,y,4);%次數
p5=polyfit(x,y,5);
xcurve=-3.5:0.1:7.2;%生成x的值
p3curve=polyval(p3,xcurve);
p4curve=polyval(p4,xcurve);%計算在這些x點的多項式
p5curve=polyval(p5,xcurve);
plot(xcurve,p3curve,'--',xcurve,p4curve,'-.',xcurve,p5curve,'-',x,y,'*');
lx=[-1 1.5];
ly=[0 0];
hold on
plot(lx,ly,'--',lx,ly-1.3,'-.',lx,ly-2.6,'-');
text(2, 0,'degree3');
text(2, -1.3,'degree4');
text(2, -2.6,'degree5');


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM