%% Load my model 
dataModel    = loadModel('OneStep');


%% Simulatate our "real model"
% we use the nominal model to generate some data
exp1 = constructExperiment(30*60, 10);
data = simulate(dataModel, exp1);


%% Scramble the parameters onthe model
m   = dataModel;
m.p = m.p.*random('log',0,1,size(dataModel.p));
m   = postProcessModel(m);

beforeFit = simulate(m, exp1);

tData = [0, logspace(0, log10(29*60), 10)];
myData.y = data.y(tData);
myData.t = tData;


% Plot the data and the model before the fit on the same axis
figure(1);
plot(myData.t, myData.y, 'o'); hold on;
drawnow;
plot(beforeFit.t, beforeFit.y(beforeFit.t), '--'); hold off;
disp('Hit any Key to continue'); pause;


%% Fit the new model to data generated from the old model
figure(2);
obj = constructObjectiveOutputSSE(m, 1:m.nY, myData);
[mFit,G] = fitParameters(m, obj, exp1);
afterFit = simulate(mFit, exp1);


%% Plot the results
figure(3);
plot(myData.t, myData.y, 'o'); hold on;
plot(beforeFit.t, beforeFit.y(beforeFit.t), '--');
plot(afterFit.t, afterFit.y(afterFit.t), '-');
hold off;