模型一: 线性模型
代码如下:
W=[56,62,69,77,85,94,105];
Y=[305,327,358,380,394,418,436];
p=polyfit(W,Y,1);
Y1=polyval(p,W);
plot(W,Y,'rx');
hold on;
plot(W,Y1,'b');
legend('原数据','模型一')
W=[56,62,69,77,85,94,105];
Y=[305,327,358,380,394,418,436];
f1=@(X,W)X*W.^(2/3);
[X,cansha]=lsqcurvefit(f1,1,W,Y);
Y2=f1(X,W);
plot(W,Y,'rx');
hold on;
plot(W,Y2,'b');
legend('原数据','模型二');
模型三: 幂函数改进模型
代码如下:
W=[56,62,69,77,85,94,105];
Y=[305,327,358,380,394,418,436];
a=[1,2];
f2=@(a,W)a(1)*(W-a(2)).^(1/3);
[a,cansha2]=lsqcurvefit(f2,a,W,Y);
Y3=f2(a,W);
plot(W,Y,'rx');
hold on;
plot(W,Y3,'m');
legend('原数据','模型三');
运行结果: