MATLAB Polynomial Fitting

matlab polynomial fitting

It is relatively simple to use matlab to realize polynomial fitting, and it can be realized with a few lines of commands.

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');

The fitting effect is as follows.
insert image description here

Guess you like

Origin blog.csdn.net/ruredfive/article/details/122997102