How can I fix my MATLAB code for the simulation of a rate equation?

  • Thread starter Thread starter almesba
  • Start date Start date
  • Tags Tags
    Rate Simulation
AI Thread Summary
The MATLAB code for simulating a rate equation is not producing any output, resulting in a blank graph. The user reports that there are no errors, but variables N and S are not defined beyond their initial index, which causes issues in subsequent iterations. Key variables like I, N, and S need proper initialization and updates within the loop to ensure calculations are valid. The discussion emphasizes the importance of defining all variables before use and correctly updating arrays in iterative processes. Addressing these issues should resolve the blank graph problem.
almesba
Messages
5
Reaction score
0
i have try this rate equation code in MATLAB. but its not working. can anyone help me please!
mm=0;

for I = 0.1e-3:0.1e-3:4.5e-3;
m=mm+1;
q=1.6e-19;
alpha=2;
Tn=3e-9;
Tp=1e-12;
G0=0.6;
N0 = 1e24;

Gamma=.2;
epsilon=1e1;
Va=3.7e-14;
tini=0;
tfin=4e-9;
dt=1e-12;
N(1)=0;
S(1)=0;
p=G0*N(m)*S(m);
l=1+epsilon*S(m);
y=q*Va;
for t=tini:dt:tfin
delN=(I/y)-(N(m)/Tn)-(p/l);



end

end

tt=t;
tt=tt*1e9;
figure(1);
plot(tt,N);
 
Last edited by a moderator:
Engineering news on Phys.org
I'm not sure whether Matlab requires that you define your variables before attempting to execute them, but I see that line 4, for example, (I0 = N0*q*Va/Tn;) contains several variables you do not define until later in your routine.
 
almesba said:
i have try this rate equation code in MATLAB. but its not working. can anyone help me please!
mm=0;

for I = 0.1e-3:0.1e-3:4.5e-3;
m=mm+1;
q=1.6e-19;
alpha=2;
Tn=3e-9;
Tp=1e-12;
G0=0.6;
N0 = 1e24;

Gamma=.2;
epsilon=1e1;
Va=3.7e-14;
tini=0;
tfin=4e-9;
dt=1e-12;
N(1)=0;
S(1)=0;
p=G0*N(m)*S(m);
l=1+epsilon*S(m);
y=q*Va;
for t=tini:dt:tfin
delN=(I/y)-(N(m)/Tn)-(p/l);



end

end

tt=t;
tt=tt*1e9;
figure(1);
plot(tt,N);

Welcome to the PF. What do you mean by "not working"? Does MATLAB throw an error somewhere, or does the program run and not give a reasonable answer?
 
berkeman said:
Welcome to the PF. What do you mean by "not working"? Does MATLAB throw an error somewhere, or does the program run and not give a reasonable answer?

MATLAB isn't throwing any error. NOT WORKING means i am getting a white or blank graph. i have tried with different axis values but still no result.
 
Code:
p=G0*N(m)*S(m);
l=1+epsilon*S(m)

Both those lines are bound to throw an error on the second iteration because neither N() or S() are defined past an index of 1.
 
While I was rolling out a shielded cable, a though came to my mind - what happens to the current flow in the cable if there came a short between the wire and the shield in both ends of the cable? For simplicity, lets assume a 1-wire copper wire wrapped in an aluminum shield. The wire and the shield has the same cross section area. There are insulating material between them, and in both ends there is a short between them. My first thought, the total resistance of the cable would be reduced...
Hi all I have some confusion about piezoelectrical sensors combination. If i have three acoustic piezoelectrical sensors (with same receive sensitivity in dB ref V/1uPa) placed at specific distance, these sensors receive acoustic signal from a sound source placed at far field distance (Plane Wave) and from broadside. I receive output of these sensors through individual preamplifiers, add them through hardware like summer circuit adder or in software after digitization and in this way got an...
I am not an electrical engineering student, but a lowly apprentice electrician. I learn both on the job and also take classes for my apprenticeship. I recently wired my first transformer and I understand that the neutral and ground are bonded together in the transformer or in the service. What I don't understand is, if the neutral is a current carrying conductor, which is then bonded to the ground conductor, why does current only flow back to its source and not on the ground path...
Back
Top