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

In summary: So, for the second iteration, you are trying to multiply or add into an undefined variable.In summary, the conversation discusses a code written in MATLAB that is not working and the speaker is seeking for help. The code entails defining variables and executing them, but there seems to be an issue with the program as it is not giving a reasonable answer and only produces a blank graph. Further examination reveals that there are errors in the code, specifically with variables N() and S() not being defined past an index of 1.
  • #1
almesba
5
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
  • #2
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.
 
  • #3
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?
 
  • #4
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.
 
  • #5
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.
 

1. What is a rate equation?

A rate equation is a mathematical representation of how the concentration of a substance changes over time in a chemical reaction or physical process. It describes the relationship between the concentrations of the substances involved and the rate at which the reaction or process occurs.

2. Why is simulation of rate equation important?

Simulation of rate equation allows scientists to predict and understand the behavior of a chemical reaction or physical process. By using mathematical models, researchers can simulate various scenarios and make predictions about the rate of the reaction or process under different conditions.

3. What factors are considered in simulation of rate equation?

The factors that are considered in simulation of rate equation include the initial concentrations of the reactants, the temperature, the presence of catalysts, and any other factors that may affect the rate of the reaction or process.

4. What are the limitations of simulation of rate equation?

One limitation of simulation of rate equation is that it is based on simplified models and assumptions, which may not accurately reflect the complexity of real-world reactions and processes. Additionally, experimental data may not always match the predicted results from the simulation.

5. How can simulation of rate equation be used in real-world applications?

Simulation of rate equation has many real-world applications, including in the development of new drugs, understanding and optimizing industrial processes, and predicting the effects of environmental changes on chemical reactions. It can also be used to design and optimize experiments and to troubleshoot issues in chemical reactions and processes.

Similar threads

Replies
1
Views
332
  • Electrical Engineering
2
Replies
43
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Advanced Physics Homework Help
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • Electrical Engineering
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • Advanced Physics Homework Help
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
Back
Top