n =5;%polyfit 返回值p从左到右是高次到低次的多项式p(x)的系数,长度是n+1%p(x)= p1 *x(n次方) + p2 *x(n-1次方)+ 。。。 + pn * x + pn+1
p =polyfit(x,y,n);
f1 =polyval(p,x);%plot(x,f1,'r-');%获得多项式的方程
syms m
for k =1:n+1var(k)= m ^(k -1);
end
func =flip(var).* p;
f =sum(func);
m =min(x):max(x);scatter(x,y,'o');hold on;
handles1 =plot(m,subs(f));hold on;%找曲线的最大最小值,即曲线的上下顶点
result =subs(f);
max_f =max(result(:));
min_f =min(result(:));line([min(x),max(x)],[max_f,max_f],'linestyle','--');hold on;%画顶点线
line([min(x),max(x)],[min_f,min_f],'linestyle','-');hold on;%画顶点线
pause(2);%cla reset;这个语句可以实现figure图像的清空
%vap(x)将分数转换为小数
推荐网址,比较全面 https://blog.csdn.net/zengxiantao1994/article/details/77943305
n =3;
x = new_HU_data;
y_w = new_WATER_data;%polyfit 返回值p从左到右是高次到低次的多项式p(x)的系数,长度是n+1%p(x)= p1 *x(n次方) + p2 *x(n-1次方)+ 。。。 + pn * x + pn+1
p =polyfit(x,y_w,n);
Funtion_w =polyval(p,x);%%%%% funtion, input x, don't change p, get new Y
二 每个数据点都不能丢失,要想连接所有的数据点
x =[1.00001.50002.00003.00004.00005.00006.00008.000010.000015.000020.000030.000040.000050.000060.000080.0000100.0000150.0000];
y =[1.57000.53550.30923.19202.77700.97840.45290.24500.14700.06470.03390.01030.00450.00140.00070.00040.00030.0002];
xx =x(1):1:x(end);
yy =spline(x,y,xx);plot(x,y,'o',xx,yy);