for loop within an odes15 function, and plot on one graph
이전 댓글 표시
K=30;
lambda1=1;
lambda2=2;
T_final = 10;
f1 = figure;
figure(f1);
hold on
[t,M] = ode15s(@(t,M) RHS_focus(M,K,lambda2,lambda1), [0 T_final], [0 100]);
plot(t,M(:,1:K)','k--')
function dMdt=RHS_focus(M,K,lambda1,lambda2)
dMdt = zeros(K,1);
dMdt(1) = lambda2*M(2) - lambda1*M(1); % Note that this is for state 0.
for i= 2:K-1
dMdt(i) = lambda1*M(i-1) - (lambda1+lambda2)*M(i) + lambda2*M(i+1); % For state 1 to 28
end
dMdt(K) = lambda1*M(K-1) - lambda2*M(K); % For state 29
dMdt= M';
end
ERROR: Index exceeds the number of array elements. Index must not exceed 2.
It didnt work when i didnt use a for loop either.
I want to plot 30 ODES on one graph.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
