16 lines
270 B
Matlab
16 lines
270 B
Matlab
n = 40;
|
|
xmin = 2.2;
|
|
xmax = 3.9;
|
|
c = 6.0;
|
|
noise = 50.0;
|
|
|
|
% generate data:
|
|
x = rand(n, 1) * (xmax-xmin) + xmin;
|
|
yest = c * x.^3;
|
|
y = yest + noise*randn(n, 1);
|
|
|
|
% compute mean squared error:
|
|
mse = mean((y - yest).^2);
|
|
|
|
fprintf('the mean squared error is %.0f kg^2\n', mse)
|