2020-05-08

%采用最小二乘法拟合曲线
clear
clc
x=[3,6,8,10,18.5,20,23,35,43.7,35];
y=[-8,-6.45,-5.1,-4,-3,-1.95,-1.5,-0.4,0.2,-0.75];

%coefficient=polyfit(x,y,1); %用一次函数拟合曲线,想用几次函数拟合,就把n设成那个数
%y1=polyval(coefficient,x);
%plot(x,y,‘o’,x,y1,’-’)
%%同样的二次拟合
coefficient=polyfit(x,y,2); %用一次函数拟合曲线,想用几次函数拟合,就把n设成那个数
y1=polyval(coefficient,x);
plot(x,y,‘o’,x,y1,’-’)
coefficient =

0.1837   -6.8101

你可能感兴趣的:(笔记)