First paragraph, second day-fitting

Fitting problem

Least squares fitting

Insert picture description here

Linear fit

Insert picture description here
Insert picture description here

Polynomial fitting

Insert picture description here
Insert picture description here
Insert picture description here

Nonlinear fitting that can be transformed into linear fitting

Insert picture description here

Polynomial curve fitting function

polyfit()

Call format

p=polyfit(x,y,n)
[p,s]=polyfit(x,y,n)
Explanation: x and y are the data points, n is the polynomial order, and return p is the polynomial coefficient vector p with power from high to bottom. The matrix s is used to generate an error estimate of the predicted value.

Case

x 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 10
and .3 .5 1 1.4 1.6 1.9 .6 .4 .8 1.5 2

Fit a polynomial

x=0:.1:1;
y=[.3 .1 1 1.4 1.6 1.9 .6 .4 .8 1.5 2]
n=3;
p=polyfit(x,y,n)
xi=linspace(0,1,100);
z=polyval(p,xi);
plot(x,y,'o',xi,z,'k',x,y,'b')

z=polyval(p,xi);
plot(x,y,‘o’,xi,z,‘k’,x,y,‘b’)


![在这里插入图片描述](https://img-blog.csdnimg.cn/20200915165413868.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTgyMjYzOA==,size_16,color_FFFFFF,t_70#pic_center)

Guess you like

Origin blog.csdn.net/weixin_45822638/article/details/108603210