Error: Attempted to access N(2); index out of bounds because numel(N)=1
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!