?? e454.m
字號(hào):
%----------------------------------------------------------------------
% Example 4.5.4: Least Squares Fit with Noise
%----------------------------------------------------------------------
% Initialize
clc
clear
n = 100;
m = 3;
noise = 0.5;
b = 3.2;
x = linspace (0,b,n)';
y = randu (n,1,-noise,noise);
X = [x x];
Y = zeros (n,2);
% Initialize arrays
fprintf ('Example 4.5.4: Least-Squares Fit with Noise\n');
for i = 1 : n
c = x(i);
y(i) = y(i) + c*(c-1)*(c-3);
Y(i,2) = y(i);
end
% Find least-squares fit
a = polyfit (x,y,m);
Y(:,1) = polyval (a,X(:,1));
graphxy (X,Y,'Least-Squares Fit with Noise','x','y','d')
%----------------------------------------------------------------------
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -