function UP_parameter_estimation_2 %(k)
% Estimate parameters in comparison to measurements of cell survival over 
% ampicillin concentration in the medium
% using the globals:
global KPLUSEINS;
global KMINUSEINS;
global KEXPRPROT;
global KPLUSZWEI;
global KMINUSZWEI;
global KATALYSE;
global KATALYSEZWEI;
global KEXPRTOR;
global KTRANSTOR;
global KTRANSAMP;
global KDEGREINS;
global KDEGRZWEI;
global AMPNULL;
global ALPHA

% parameter settings needed from t1 onwards:
% conzentration(t0) of Microviridin = 3000 molecules if present
KPLUSEINS =  8.e-6;
Kplus1 = KPLUSEINS*(6.022*1.e+23)*(9.e-16);
KMINUSEINS = 4.e-4;
KD = KMINUSEINS/Kplus1;
KEXPRPROT =  0.6; %Protease expression activated
KDEGREINS =  17.e-4;

% parameter settings needed from t2 onwards:
KPLUSZWEI =  (2.0253)*(1.e-5); % gained by parameter estimation
KMINUSZWEI = 2.e-4; 
KATALYSE =   8; 
KEXPRTOR =   1;
KDEGRZWEI =  2.e-3;
KTRANSTOR =  1.e-3;

% parameter settings needed from t3 onwards:
KTRANSAMP = 5.e-3;
KATALYSEZWEI = 0.001;
%AMPNULL = 8.e+2; value in case it is not changed as in this program

% parameter settings needed for conversion:
ALPHA = 0.3163; % gained by parameter estimation

% FIT SETTING
% KPLUSZWEI = k(1)

% LOOP for the calculation of a survival rate vector at different
% initial concentrations of ampicillin in the medium
for n=0:50:800                 %parameter range
    %using parameter: increasing and solving ODEs in each loop cycle
    N = ((n*(3.e-17))*(6.022*1.e23))*((349.41)^-1)*(1.e-3);
    AMPNULL = N;
    q = fix((n/50)+1);
    %--- solving odes
    conzini1 = [0 , 0 , 0]'; %3000
    [t1, csol1] = ode23s('conzt1', 3600, conzini1);
    l1=length(t1);
    %--- solving odes
    conzini2 = [csol1(l1,1) , csol1(l1,2) , csol1(l1,3) , 0 , 0 , 0]';
    [t2, csol2] = ode23s('conzt2', 3600, conzini2);
    l2=length(t2);
    %--- solving odes
    conzini3 = [csol2(l2,1) , csol2(l2,2) , csol2(l2,3) , csol2(l2,4) , csol2(l2,5) , csol2(l2,6), 0]';
    [tNR, csolNR] = ode23s('conzt3', (0:10:3000), conzini3);
    l3=length(tNR);
    %---
    %calculate Ampicillin concentration in µg/mL out of N Molecules
    %using specific weight, perplam volume and Avogrado const.
    vek11 = ((csolNR(:,7).*((3.e-17)^(-1))).*((6.022*1.e23)^(-1))).*(349.41).*(1.e+3);
    %calculate cell surviving rate out of Ampicillin concentration in µg/mL
    vek13 = 25/(20+(10.*2.^((ALPHA.*vek11(l3))-1)));
    %
    M(q)=vek13;
    %T(:,q)=tNR; only neesed for plotts (X over time)
end

% create vectors for parameter estimation
SurvivalModel= 100*[M(1), M(2), M(3), M(5), M(7), M(9), M(16), M(17)]
% measurement conditions:
Amp0Med = [0, 50, 100, 200, 300, 400, 750, 800];
% mesurement results (survived cells),lacatamase and protease expression:
Survival = [100, 55, 0, 0, 0, 0, 0, 0];

% calculate quardatic error (resid)
% resid = Survival - SurvivalModel;
% val2 = resid*resid';

plot(Amp0Med,Survival,'r-',Amp0Med,SurvivalModel,'b-')
xlabel('Amp_M_e_d in µg/mL');
ylabel('Percentage of surviving cells');
title('Potsdam Bioware: survival rate of cells, lactamase & protease expression induced');
legend('Measurement','Model',2);

% code for parameter estimation:
% [k SSEmin]=fminsearch('FittedModel_03_1',k)
% optional settings:
% options=optimset('MaxFunEvals',10000,'MaxIter',10000);
end

