Matlab进行多项式拟合

觉得有用的先点赞后收藏,不要只收藏不点赞!!

1⃣️一个坐标系里面绘制多个函数图像

clear
clc
x = [0  10 20 30  40  50   60  70  80  90 100 110  120];
y = [5  1 7.5  3 4.5 8.8 15.5 6.5  -5 -10  -2  4.5  7 ];
p5=polyfit(x,y,5);%5阶多项式拟合
y5=polyval(p5,x);
p5=vpa(poly2sym(p5),5);
p9=polyfit(x,y,9);%9阶多项式拟合
y9=polyval(p9,x);
figure;%画图显示
plot(x,y,'bo');
hold on;
plot(x,y5,'r');
plot(x,y9,'g--');
legend('原始数据','5阶多项式拟合','9阶多项式拟合');
xlabel('x');
ylabel('y');

在这里插入图片描述

2⃣️一个GUI里面绘制多个坐标图像


clear
clc
x=0:0.2:2;
y=(x.^2-3*x+5).*exp(-3*x).*sin(x);
xi=0:0.03:2;%要插值的数据
yi_nearest=interp1(x,y,xi,'nearest');
yi_linear=interp1(x,y,xi);
yi_spine=interp1(x,y,xi,'pchip');
yi_pchip=interp1(x,y,xi,'pchip');
yi_v5cubic=interp1(x,y,xi,'v5cubic');
figure;
hold on;
subplot(231);
plot(x,y,'ro');
title('已知数据点');
subplot(232);
plot(x,y,'ro',xi,yi_nearest,'b-');
title('临近点插值');
subplot(233);
plot(x,y,'ro',xi,yi_linear,'b-');
title('线性插值');
subplot(234);
plot(x,y,'ro',xi,yi_spine,'b-');
title('3次样条插值');
subplot(235);
plot(x,y,'ro',xi,yi_pchip,'b-');
title('分段3Hermite插值');
subplot(236);
plot(x,y,'ro',xi,yi_v5cubic,'b-');
title('MATLAB5种三次多项式插值');

在这里插入图片描述

  • 33
    点赞
  • 114
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿维的博客日记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值