Array indices must be positive integers or logical values.
Show older comments
Hello,
I have been trying to run the code below. I have gotten everything to work for lines 14 & 15, but I cannot figure out what is wrong with line 16 (NC_t). I receieve the follow error upon running the program:
"Array indices must be positive integers or logical values."
May someone help explain where something is going wrong? I would greatly appreciate the help.
Thanks!
clc;
clear all;
n=51;
NA_0=100; % Initial Condition for N1
NB_0=0; % Initial Condition for N2
NC_0=0; % Inital Condition for N2
Lambda_0=0.3429; % Decay Constant for N_1 (hr^-1)
Lambda_1=.076154; % Decay Constant for N_2 (hr^-1)
t(1)=0; % (hr)
dt=1; % (hr)
for i=1:n
t(i)=i*dt-dt;
NA_t(i)=NA_0*exp(-1*Lambda_0*t(i));
NB_t(i)=NB_0*exp(-1*Lambda_1*t(i))+(Lambda_0*NA_0)/(Lambda_1-Lambda_0)*(exp(-1*Lambda_0*t(i))-exp(-1*Lambda_1*t(i)));
NC_t(i)=NC_0+NB_0*(1-exp(-1*Lambda_1*t(i)))+(NA_0/(Lambda_1-Lambda_0))*(Lambda_1(1-exp(-1*Lambda_0*t(i)))-Lambda_0(1-exp(-1*Lambda_1*t(i))));
end
plot(t,NB_t,t,NA_t);
2 Comments
John D'Errico
on 2 Oct 2021
When you show a PICTURE of code, what happens is now we cannot even paste in your code nd execute it for ourselves. Everything there was purely text, so trivial to paste in directly. But now we need to read small, fuzzy pictures of text, to try to find the error in your code.
Why would you deliberately make it more difficult for someone to help you?
Joseph Wunschel
on 2 Oct 2021
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!