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.
 
Very basic question. Consider a 3-terminal device with terminals say A,B,C. Kirchhoff Current Law (KCL) and Kirchhoff Voltage Law (KVL) establish two relationships between the 3 currents entering the terminals and the 3 terminal's voltage pairs respectively. So we have 2 equations in 6 unknowns. To proceed further we need two more (independent) equations in order to solve the circuit the 3-terminal device is connected to (basically one treats such a device as an unbalanced two-port...
suppose you have two capacitors with a 0.1 Farad value and 12 VDC rating. label these as A and B. label the terminals of each as 1 and 2. you also have a voltmeter with a 40 volt linear range for DC. you also have a 9 volt DC power supply fed by mains. you charge each capacitor to 9 volts with terminal 1 being - (negative) and terminal 2 being + (positive). you connect the voltmeter to terminal A2 and to terminal B1. does it read any voltage? can - of one capacitor discharge + of the...
Thread 'Weird near-field phenomenon I get in my EM simulation'
I recently made a basic simulation of wire antennas and I am not sure if the near field in my simulation is modeled correctly. One of the things that worry me is the fact that sometimes I see in my simulation "movements" in the near field that seems to be faster than the speed of wave propagation I defined (the speed of light in the simulation). Specifically I see "nodes" of low amplitude in the E field that are quickly "emitted" from the antenna and then slow down as they approach the far...
Back
Top