p7_2.m

来自「Advanced Engineering Mathematics using M」· M 代码 · 共 19 行

M
19
字号
% P7_2.M  Least squares fit of a line to data%x=[6.1 7.6 8.7 10.4];y=[0 2 4 6];%A1=[1 1 1 1];A=[A1' x'];fprintf('Coefficients')xlsq=A'*A \ A'*y'%fprintf('Equation: %fx  %f\n',xlsq(2),xlsq(1));%xplot=[6.1:0.01:10.4];yplot=xlsq(2).*xplot + xlsq(1);plot(x,y,'o',xplot,yplot,'-')title('Least squares line for spring')%% Add a few comments and annotate plot.%

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?