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
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
2022년 9월 24일
Try ode23s() as I suspect that your system is stiff.
MARIA
2022년 9월 24일
Torsten
2022년 9월 24일
Did you see above that the concentration of "ES" blows up ?
MARIA
2022년 9월 24일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
