need to use this analytical solution to plot the absolute percent error in the concentration A at each time step for Euler's method

2 ビュー (過去 30 日間)
%% Euler
nsteps = 12;
t = zeros (nsteps,1);
A = zeros (nsteps,1);
B = zeros(nsteps, 1);
P = zeros(nsteps,1);
A(1) = 1;
B(1) = 3;
C(1) = 0;
K = 5*10^-5;
for k = 2:13
t(k) = t(k-1)+3600;
A(k) = A(k-1)+(-K*A(k-1)*B(k-1))*3600;
B(k) = B(k-1)+(-Yb*(K*A(k-1)*B(k-1)))*3600;
P(k)= P(k-1)+ Yp*(K*A(k-1)*B(k-1))*3600;
end
timestep is 3600 sec
  3 件のコメント
Naveen Krish
Naveen Krish 2022 年 3 月 18 日
I need to plot the absolute percent error in the concentration of A at each timestep of 3600sec from ti=0 to tf=12 hours using Eulers method
Sam Chak
Sam Chak 2022 年 3 月 18 日
編集済み: Sam Chak 2022 年 3 月 18 日
You have been posting some "questions" in the last few days. If you don't want the question get "pruned" again, I suggest you to use the following template:
––– Template begins –––
Hi, I'm doing a <project> to solve this <problem> with the following <Math Equations> (in LaTeX form or in image). I have wrriten the code but I ran into some issues and received an error message OR need to do some <additional tasks>. I have tried searching in MATLAB Answers pertaining to my topics of study, but to no avail. The MATLAB code and the error message are shown below:
Click the circled icon to insert the MATLAB code and error message.
I have also attached the code/data for your convenience. I appreciate your help with troubleshooting the <problem>. OR Thanks for considering my request.
––– Template ends –––

サインインしてコメントする。

回答 (1 件)

VBBV
VBBV 2022 年 3 月 29 日
nsteps = 12;
t = zeros (nsteps,1);
A = zeros (nsteps,1);
B = zeros(nsteps, 1);
P = zeros(nsteps,1);
A(1) = 1;
B(1) = 3;
C(1) = 0;
K = 5*10^-5;
Yp = 1.34; % e,g, values
Yb = Yp/2; % e.g
for k = 2:13
t(k) = t(k-1)+3600;
Aold = A(k-1);
A(k) = A(k-1)+(-K*A(k-1)*B(k-1))*3600;
B(k) = B(k-1)+(-Yb*(K*A(k-1)*B(k-1)))*3600;
P(k)= P(k-1)+ Yp*(K*A(k-1)*B(k-1))*3600;
Aps(k) = abs((A(k)-Aold)/A(k))*100; % absolute percent error
end
plot(Aps);title('Absoulte % error'); ylabel('%'); xlabel('timestep')
Check with values for Yb and Yp . i have used them here for e.g. purpose
  1 件のコメント
Torsten
Torsten 2022 年 3 月 29 日
A(k-1) and A(k) are the solutions for A at times t(k-1) and t(k). Thus the difference A(k) - A(k-1) is an indicator on how much the solution changes with time (so something like A'(t(k))*dt), but not an error in the Euler integration.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by