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 个评论
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
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!