MATLAB多项式拟合

matlab多项式拟合

使用matlab实现多项式拟合比较简单,几行命令就能实现。

clc;clear;
close all;

len = 20;                       %  数据长度
x = 1:1:len;                    %  时间轴坐标
y = x.^6;                       %  生成6次多项式                 
figure,plot(x,y,'o');
xlabel('Position / s');
ylabel('Intencity / cd');
title('Input Signal');

% 多项式拟合
coef = polyfit(x,y,4);          %  拟合4阶多项式
coee = polyval(coef,x);         %  使用拟合系数生成以x为坐标的多项式
hold on,plot(x,coee);           %  绘图命令
legend('Initial Curve','Fitting Curve');

拟合效果如下。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/ruredfive/article/details/122997102