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

1 次查看(过去 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 CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by