Error: Attempted to access N(2); index out of bounds because numel(N)=1

조회 수: 1 (최근 30일)
carl chew
carl chew 2013년 10월 3일
function results=decay_a2b2c(half_lives,N0,time_units,time_span)
% Calculate decay constant
lambda=log(2)./half_lives(:);
% Call the ODE45 function
[t,N]=ode45(@decay_rate,[0 time_span],N0); results=[t N];
% Plot results
figure
set(gcf,'color','white')
set(gca,'Fontsize',12,'Fontweight','bold')
plot(t,N,'Linewidth',2)
grid on
xlabel(['Time(' time_units ')'],'Fontsize',12,'Fontweight','bold')
ylabel('N(t)','Fontsize',12,'Fontweight','bold')
legend('A','B','C',0)
title_a=['t_{1/2,A}=' num2str(half_lives(1)) ' ' time_units];
title_b=['t_{1/2,B}=' num2str(half_lives(2)) ' ' time_units];
title_c=['t_{1/2,C}=' num2str(half_lives(3)) ' ' time_units];
title([title_a ', ' title_b ', ' title_c])
function dNdt=decay_rate(t,N)
A=[-N(1) 0 0; N(1) -N(2) 0; 0 N(2) 0];
dNdt(N)=A*lambda;
end
end
-------
decay_a2b2c(489,6.004E22,'sec',2000)
%

답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by