My code is running too long

Below you will find my code. I am having a problem running the code for more than 100 seconds (tlast). For 100 seconds I get a graph in my output. However, for more than 100 seconds it keeps running and does not give me any output. What is wrong with my code?
tic
global k1 kminus1 k2 kminus2
k1 = 0.1 ;
kminus1 = 0.1 ;
k2 = 0.3 ;
kminus2 = 0.05 ;
% dt = 0.001 ;
tlast = 100 ;
% iterations = round(tlast/dt) ;
S = 1.0 ;
E = 0.1 ;
ES = 0 ;
P = 0 ;
X = [S;E;ES;P] ;
% time = dt*(0:iterations-1) ;
[time2,X_all2] = ode45(@dXdt2,[0,tlast],X) ;
S_all = X_all2(:,1) ;
E_all = X_all2(:,2) ;
ES_all = X_all2(:,3) ;
P_all = X_all2(:,4) ;
figure
hold on
plot(time2,X_all2(:,1),'k','LineWidth',2)
plot(time2,X_all2(:,2),'g','LineWidth',2)
plot(time2,X_all2(:,3),'b','LineWidth',2)
plot(time2,X_all2(:,4),'r','LineWidth',2)
xlabel('time (s)')
ylabel('Concentration (uM)')
sgtitle ('Concentration vs. Time')
legend('S','E','ES','P')
toc
Elapsed time is 0.611294 seconds.
Below is the function used to pull the numbers for the plot:
function dX_2 = dXdt2 (t,X)
global k1 kminus1 k2 kminus2
S = X(1) ;
E = X(2) ;
ES = X(3) ;
P = X(4) ;
dS = -k1*S*E + kminus1*ES ;
dE = -k1*S*E + kminus1*ES + k2*ES -kminus2*E*P ;
dES = k1*S*E - kminus1*ES + kminus2*E*P ;
dP = k2*ES - kminus2*E*P ;
dX_2 = [dS;dE;dES;dP] ;
end

댓글 수: 5

Walter Roberson
Walter Roberson 2022년 9월 24일
Try ode23s() as I suspect that your system is stiff.
MARIA
MARIA 2022년 9월 24일
Hello!
I tried doing that for 300 seconds but it gave me the following error:
Warning: Failure at t=2.469706e+02. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (8.774157e-13) at time t.
Torsten
Torsten 2022년 9월 24일
Did you see above that the concentration of "ES" blows up ?
MARIA
MARIA 2022년 9월 24일
Hello!
Yes, that should be correct since I am trying to model the conversion of Enzyme and Product back to an Enzyme-Substrate Complex. I'm modeling it as a reversible reaction.
Torsten
Torsten 2022년 9월 24일
편집: Torsten 2022년 9월 24일
But 3.5e7 mol/m^3 seems a little high after t=100 :-)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2022년 9월 24일

편집:

2022년 9월 24일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by