The following MATLAB code segment creates a synthetic data set by adding noise to
. You should supply the value of , which is the number of data points to be generated.
% --- Generate synthetic data
x0 = 0.01; % Starting point ~= 0 avoids log(0)
noise = 0.05; % Magnitude of noise
x = linspace(x0,2,n);
y = 5*x.*exp(-3*x);% Create the true function y = g(x)
yn = y + noise*(rand(size(x))-0.5); %Noise multiplies
% random values v in the range
% -0.5 <= v <= 0.5
yn = abs(yn); % Make sure all data are positive