Tspan = linspace(0,1.8e3,5000);

Et = 1;
S  = 1000;

[t u] = ode15s('diff', Tspan, [Et S 0 0 0]);

%b)
figure(1)
plot(t,u(:,1:4),t,u(:,1)+u(:,3),'--',t,u(:,5),'-.')
%title('Chymotrypsin (P) d[E]/dt=1 d[S]/dt=2 d)')
xlabel('Tid(s)')
ylabel('Koncentration (mM)')
legend('E','S','ES','P','E_t','PM')
grid

%b) i)
%plot(t,gradient(u(:,3),t))
%title('Gradienten av enzymkomplexet ES')
%xlabel('Tid(s)')
%ylabel('d[ES]/dt (M s^-^1)')
%grid

%Minsta kvadratmetoden
A  = [1./u(:,2) ones(length(u),1)];
y  = 1./gradient(u(:,4),t);
b  = A\y;
k2 = 1/(Et*b(2))
KM = b(1)*k2*Et

%Feluppskattning c) iii)
%P  = u(:,4);
%PM = u(:,5);
%figure(2)
%plot(t,P,'r--',t,0.95*P,'r--',t,PM);
%title('Feluppskattning av Michaelis-Mentens ekvation')
%legend('P','0.95P','PM (E_t=1/2)')
%xlabel('Tid(s)')
%ylabel('Koncentration (M)')
%grid

%Omsättningsgrad
%x=1-u(:,2)/2;
%figure(3)
%hold on
%plot(t,x,'g')
%legend('b) iii)','d) ii)','d) iv)')

%produktutbyte d) v)
%figure(2)
%plot(t,u(:,4),'m')
%grid
