필터 지우기
필터 지우기

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에서 Introduction 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