ex7_3.m
来自「Advanced Engineering Mathematics using M」· M 代码 · 共 29 行
M
29 行
% EX7_3.M Least-squares curve fit with a line using% \ operator and polyfit. The results are displayed% and plotted.x=[0 1 2 3 5]; % Define the data pointsy=[0 1.4 2.2 3.5 4.4];A1=[1 1 1 1 1 ]'; % Least squares matrixA=[A1 x'];Als=A'*A;bls=A'*y';% Compute least squares fit Xlsq1=Als\bls;Xlsq2=polyfit(x,y,1);f1=polyval(Xlsq2,x);error=y-f1;disp(' x y f1 y-f1')table=[x' y' f1' error'];disp(table)fprintf('Strike a key for the plot\n')pause% Plotclfplot(x,y,'o',x,f1,'-')axis([-1 6 -1 6])title('Least Squares line Figure 7.3')xlabel('x')ylabel('y')%% Modify the script to allow input of the data points and the% order of the least squares polynomial
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?