My code is running too long
Ältere Kommentare anzeigen
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
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 Kommentare
Walter Roberson
am 24 Sep. 2022
Try ode23s() as I suspect that your system is stiff.
MARIA
am 24 Sep. 2022
Torsten
am 24 Sep. 2022
Did you see above that the concentration of "ES" blows up ?
MARIA
am 24 Sep. 2022
Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
