To plot the absolute percent error

์กฐํšŒ ์ˆ˜: 2 (์ตœ๊ทผ 30์ผ)
Naveen Krish
Naveen Krish 2022๋…„ 3์›” 18์ผ
๋Œ“๊ธ€: Naveen Krish 2022๋…„ 3์›” 18์ผ
Hi, I'm doing a project on formation of disinfection byproducts during water treatment to solve this problem i have to plot the absolute percent error in the concentration A at each timestep of 3600 secs from ti = 0 to tf=12 hours. I need to compare the results between Euler's method and 4th order RK. I have wrriten the code but need to determine the absolute percent error. 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:
%%Eulers method
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
%%RK Method
h=3600;
A0=1;
B0=3;
P0=0;
K=5*10^-5;
Yb=1;
Yp=0.15;
t = 0:h:43200;
fyt = @(t,y) [(-K*y(1)*y(2));
(-Yb*(K*y(1)*y(2)));
(Yp*(K*y(1)*y(2)))];
Y = zeros(3,numel(t))
Y(1,1) = 1.0;
Y(2,1) = 3.0;
Y(3,1) = 0;
for i=1 : numel(t)-1
k1 = fyt(t(i),Y(:,i));
k2 = fyt(t(i)+0.5*h,Y(:,i)+0.5*h*k1);
k3 = fyt(t(i)+0.5*h,Y(:,i)+0.5*h*k2);
k4 = fyt(t(i)+h,Y(:,i)+h*k3);
Y(:,i+1) = Y(:,i) + (h/6)*(k1+2*k2+2*k3+k4);
end
For the following parameter values: ๐‘Œ๐ต = 1, ๐‘Œ๐‘ƒ = 0.15, ๐ด0 = 1 mg/L, ๐ต0 = 3 mg/L, ๐‘ƒ0 = 0, ๐พ = 5E โˆ’ 5
Use the analytical solution to plot the absolute percent error in the concentration of A at each timestep for both Eulerโ€™s method and 4th order RK. (Notice how the error grows with each time step).
I have also attached the code/data for your convenience. I appreciate your help with troubleshooting the problem. Thanks for considering my request.
  ๋Œ“๊ธ€ ์ˆ˜: 2
Naveen Krish
Naveen Krish 2022๋…„ 3์›” 18์ผ
Naveen Krish
Naveen Krish 2022๋…„ 3์›” 18์ผ

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

๋‹ต๋ณ€ (0๊ฐœ)

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Mathematics์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

์ œํ’ˆ


๋ฆด๋ฆฌ์Šค

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by