【matlab_郭彦甫课堂——曲线回归分析与内插】

第十四课matlab郭彦甫 曲线回归分析与内插答案

Exercise1 :given the table below:

  1. find the β0 and β1 of the regression line
  2. plot the figure 在这里插入图片描述
clear; close all;
Temper = [20 30 40 50 60];
TC_Output = [0.025 0.035 0.050 0.060 0.080];
fit = polyfit(Temper, TC_Output,1);
xfit = [Temper(1):0.1:Temper(end)]; yfit = fit(1)*xfit + fit(2);
plot(Temper, TC_Output ,'bo',xfit,yfit,'r-'); set(gca,'fontsize',14);
xlabel('Temperature(℃)'); ylabel('TC Output(mV)');
title('Calibration of TC')
grid on ;

第一题

Exercise 2: find the 4th,5th and 6th-order polynomial;

  1. 找到如下x,y的4阶,5阶和6阶多项式的最佳系数解。
  2. QUESTION:is it better to use higher order polynomials?
    x = [-1.2 -0.5 0.3 0.9 1.8 2.6 3.0 3.5];
    y = [-15.6 -8.5 2.2 4.5 6.6 8.2 8.9 10.0];
clear ;close all;
x = [-1.2 -0.5 0.3 0.9 1.8 2.6 3.0 3.5];
y = [-15.6 -8.5 2.2 4.5 6.6 8.2 8.9 10.0];
for i = 4:6;
    subplot(1,3,i-3);p = polyfit(x,y,i);
    xfit = x(1):0.1:x(end); yfit = polyval(p, xfit);
    plot(x, y ,'ro',xfit,yfit,'b-'); set(gca,'fontsize',14);
    ylim([-17,11]),legend('Data points','Fitted curve','Location','southeast')
end

第2题

Exercise3 :fit the data using linear lines and cubic splines;

  1. 对下列数据进行线性拟合和三次样条拟合
    x = [0 0.25 0.75 1.25 1.5 1.75 1.85 2 2.125 2.25];
    y = [1.2 1.18 1.1 1 0.92 0.8 0.7 0.55 0.35 0];
clear ; close all;
x = [0 0.25 0.75 1.25 1.5 1.75 1.85 2 2.125 2.25];
y = [1.2 1.18 1.1 1 0.92 0.8 0.7 0.55 0.35 0];
plot(x,y,'ro','MarkerFaceColor','r');
xlim([0,2.5]);ylim([0,1.4]);box on;
set(gca,'Fontsize',14);
y =interp1(x,y,x);
hold on;plot(x,y,'-b','linewidth',2);
hold off;
y =spline(x,y,x);
hold on;plot(x,y,'-.g','linewidth',2);
hold off;
h = legend('original','linear','Spline');
set(h,'fontname','times new roman');

第3题

以上为matlab2021a版可操作,其他版本可以试试。如有不理解,请留言在评论区。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小熊呀~

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

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

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

打赏作者

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

抵扣说明:

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

余额充值