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
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting a MATLAB code intended for simulating a rate equation. Participants are examining issues related to variable definitions, program execution, and output results, focusing on both the technical aspects of the code and the behavior of MATLAB during execution.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant expresses that their MATLAB code is not functioning as expected but does not specify the nature of the failure.
  • Another participant questions whether MATLAB requires variables to be defined before use, pointing out that some variables in the code are not defined until later.
  • A participant seeks clarification on what "not working" means, asking if there are any error messages or if the output is simply not reasonable.
  • It is noted that the code produces a blank graph, indicating that the output is not as anticipated despite attempts to adjust axis values.
  • Concerns are raised about specific lines in the code that may lead to errors in subsequent iterations due to undefined indices for arrays N() and S().

Areas of Agreement / Disagreement

Participants do not reach a consensus on the specific issues causing the code to fail, and multiple viewpoints regarding potential errors and misunderstandings about variable definitions remain present.

Contextual Notes

There are unresolved questions regarding the initialization of arrays and the handling of indices in the code, which may affect the execution and output of the simulation.

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.
 

Similar threads

Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
1
Views
3K
Replies
3
Views
2K
  • · Replies 43 ·
2
Replies
43
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K