function sensitivity_analysis
    %Pichia secretion model_Sensitivity analysis
    
    %% function, which 2 constants should be variied
    %% please, select one of the following 3 variants
    %% SD = TSEC and TDEG, 
    %% PS = qPI and TSEC, 
    %% PD = qPI and TDEG
    
    myopt='PS';
    
    %%  starting values
    
    IH0=[0 %Fab intracellular
        0]; % Fab extracellular
  
   %% constants
   qPI = 2.38; % intracellular Fab3H6 formation (µg Fab * BTS-1 * min-1)
   qPIstart = 2.38;
   TSEC= 75.3;  % secretion  constant (min), 
   TDEG= 45.8;  % degradation constant (min)
   D= 0.001667; % dilution rate (min-1)
   BTS= 25;  % biomass dry substance (g L-1)
    
 
   %% function call - ordinary differential equation (ode), arguments
   %% timespan, vector ofinitial conditions (IHO)
   %% ode15s algorithm = Implicit linear multistep, orders 1 to 5
   tf=50; 
   [t Y]=ode15s(@ODEPulseChaseTIME,[0 tf],IH0); %timespan 0 - tf

   %% definiton of values for loop
   k=0;
   m=0;
   c=0;
   var=[0.1,0.111,0.125,0.143,0.1667,0.2,0.25,0.333,0.5,1,2,3,4,5,6,7,8,9,10];
   
   %r=zeros(length(var),size(Y,2),length(var));
   r=zeros(length(var),length(var));
   atsec=zeros(length(var),1);
   atdeg=zeros(length(var),1);
   aqpi=zeros(length(var),1);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%% generates values for X, Y coordinate for 
   for vc=var
       c=c+1;
       TSECc=75.3/vc;
       TDEGc=45.8/vc;
       qPIc=qPI/vc;     
       atsec(c,1)=TSECc;
       atdeg(c,1)=TDEGc;
       aqpi(c,1)=qPIc;
   end
   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if myopt == 'SD'
    %% loop to varry the values of TDEG and TSEC
    %% loop over first variable
    for j=var
        %% calculation of TSEC, relative to starting value
        TSEC=75.3/j;
        %% counter for first loop
        m=m+1;
        %% loop over second variable
        for l=var
        %% calculation of TDEG, relative to starting value
            TDEG=45.8/l;
        %% counter for second loop
            k=k+1;
            p=floor(length((t)/2));          
            %% get 2. row
            tmp=fsolve(@SSODEPulseChaseTIME,Y(p,:));
            r23(k,m)=tmp(2);
        end
        %% reset counter of the 2. loop
        k=0;
    end
    
   %% 3D-plot for TDEG, TSEC and FabM
   %% function mesh and surf
    [Xsec,Ydeg]=meshgrid(atsec,atdeg);
    surf(Xsec,Ydeg,r23)
    % Set plot to log scale for X, Y and Z axis
    set(gca, 'XScale', 'log','YScale', 'log')
    % Adds title
    title('Secretion vs Degradation');
    zlim([0 14000])
    % Adds colorbar on the side
    colorbar;
    % Adds labels for X,Y,Z axis
    xlabel('t1/2 SEC [min]');
    ylabel('t1/2 DEG [min]');
    zlabel('Fab3H6e [µg g-1]');
    % Saves plot with specified name
    saveas(gcf,'PATH where the graphic should be saved\3dKdegKsec.jpg');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

elseif myopt == 'PS'  
 %% loop to varry the values of qPI and TSEC 
   for i=var
       %% calculation of new qPI, relative to qPIstart
       %% do not forgett to change this when you want to 
       %% try new qPI values!
       qPI=qPIstart/i;
       %% counter for first loop
       m=m+1;
       for j=var;
           %% calculation of TSEC, relative to starting value
           TSEC=75.3/j;
           k=k+1;
           p=floor(length((t)/2));
           %r(k,:,m)=fsolve(@SSODEPulseChaseTIME,Y(p,:));
           tmp=fsolve(@SSODEPulseChaseTIME,Y(p,:));
           r12(k,m)=tmp(2);
       end
     k=0;
   end
   
    %% 3D-Plot for qPI, TSEC and FabM
   [Xass,Ysec]=meshgrid(aqpi,atsec);
    surf(Xass,Ysec,r12);
    set(gca, 'XScale', 'log', 'YScale', 'log')
    title('Intracellular Fab Formation vs Secretion');
    zlim([0 14000])
    colorbar;
    xlabel('qPI [µg g-1 min-1]');
    ylabel('t1/2 SEC [min]');
    zlabel('Fab3H6e [µg g-1]');  
    saveas(gcf,'PATH where the graphic should be saved\3dqPIKsec.jpg');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

elseif myopt == 'PD'
    %% loop to varry the values of qPI and TDEG 
    for i=var
        %% calculation of new qPI, relative to qPIstart
        %% do not forgett to change this when you want to 
        %% try new qPI values!
        qPI=qPIstart/i;
        m=m+1;
        for l=var
            TDEG=45.8/l;
            k=k+1;
            p=floor(length((t)/2));
            % r(k,:,m)=fsolve(@SSODEPulseChaseTIME,Y(p,:));
            tmp=fsolve(@SSODEPulseChaseTIME,Y(p,:));
            r13(k,m)=tmp(2);
        end
     k=0;
    end

    %% 3D-Plot for qPI, TDEG and FabM
   [Xass,Ydeg]=meshgrid(aqpi,atdeg);
   surf(Xass,Ydeg,r13)
   set(gca, 'XScale', 'log', 'YScale', 'log')
   title('Intracellular Fab Formation vs Degradation');
   zlim([0 14000]);
   colorbar;
   xlabel('qPI [µg g-1 min-1]');
   ylabel('t1/2 DEG [min]');
   zlabel('Fab3H6e [µg g-1]');
   saveas(gcf,'PATH where the graphic should be saved\3dqPIKdeg.jpg');
end
    
   %% Plot Y in dependence of t
   % plot(t,Y);
   % legend('Fab intracellular','Fab extracellular','Location','NorthOutside')

    function DHH=ODEPulseChaseTIME(t,h) 
        DHH=SSODEPulseChaseTIME(h);
    end

    function DHH=SSODEPulseChaseTIME(h)   
        FabI=h(1); % µg gBTS-1
        FabM=h(2); % µg gBTS-1
           
        DHH=zeros(2,1);
        DHH(1)=qPI-log(2)/(TSEC)*FabI-log(2)/(TDEG)*FabI-D*FabI; % intracellular Fab
%        DHH(1)=KASS*FabI-TSEC*FabI-TDEG*FabI-D*FabI; %Intracellular Fab
        DHH(2)=log(2)/(TSEC)*FabI-D*FabM; % extracellular Fab
              
    end

end

