%% Nonlinear regression. Generate data for a dose response curve by
%% adding some normally distributed noise to a Hill function. 

%% y(x) = ymax/(1 + (EC50/dose)^n)
%% Specify model parameters. The Hill function is given by 
ymax = 1;
Lec50 = 0;
n = 2;
modelpar = [ymax Lec50 n];

%% Generate some data
dose = (logspace(-1, 1, 15))';
yTrue = Hill(modelpar, dose);

%% Add normal error to simulate experimental noise
NoiseStd = 0.1; % The standard deviation of the noise
err = NoiseStd*randn(length(yTrue), 1);
yExpt = yTrue + err;

%% Save data as text file for use with other scripts
DoseResponse = [dose yExpt];
save('DoseResponseData.dat', 'DoseResponse', '-ascii')
