V DC DT W QC KV C: A Mass Balance For A Pollutant in A Well-Mixed Lake Can Be Written As

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

MATLAB CODE:

TASK

A mass balance for a pollutant in a well-mixed lake can be written as:

dc
v =w−Qc−kv √ c
dt

Given the parameter valuesas follows:


v=1× 106 m3
Q=1 ×10 5 m 3 / year
w=1 ×106 gm/ year
k =0.25 m 0.5 / g0.5 / year
The equation takes the form:

25 √ c+ 10 c−100=0

Solve for the steady-state concentration, find the root using Secant method in MATLAB.

PROGRAM:
%%
%%
clc
close all
clear all

f=@(x) 25*sqrt(x)+10*x-100 % Let steady-state concentration = x


f(0)
f(5)
f(10)
fplot(f,[0,10])
xlabel ('Steady-state concentration, c');
ylabel ('f(c)');
title ('Secant METHOD');
grid on
gtext('xr');

xa=0;
xb=10;
f_xa=@(x) 25*sqrt(xa)+10*xa-100;
f_xb=@(x) 25*sqrt(xb)+10*xb-100;

fprintf ('i xa xb xr f(xr) RE\n');

for i=1:8
xr=(xa*f(xb)-xb*f(xa))/(f(xb)-f(xa));
f_xr=25*sqrt(xr)+10*xr-100;
RE=abs((xr-xa)/xr)*100;
fprintf ('%6d %15.7f %15.7f %15.7f %15.7f %18.8f \n' ,
i,xa,xb,xr,f_xr,RE);
xa=xb;
f_xa=f_xb;

xb=xr;
f_xb=f_xr;

end
fprintf ('\n The root of given equation = %f \n' , xr);

OUTPUT:

f=
@(x)25*sqrt(x)+10*x-100
ans =
-100

ans =
5.9017

ans =
79.0569

i xa xb xr f(xr) RE

1 0.0000000 10.0000000 5.5848156 14.9286921


100.000000

2 10.000005.5848156 4.5569858 -1.0623985 119.4433017

3 5.5848156 4.5569858 4.6252716 0.0188273


20.74567944

4 4.5569858 4.6252716 4.6240825 0.0000253


1.45102891

5 4.6252716 4.6240825 4.6240809 -0.0000000


0.02574892

6 4.6240825 4.6240809 4.6240809 -0.0000000


0.00003454

7 4.6240809 4.6240809 4.6240809 0.0000000


0.00000000
8 4.6240809 4.6240809 4.6240809 0.0000000
0.00000000

The root of given equation = 4.624081

GRAPH:

SECANT METHOD

50 xr

0
f(c)

-50

-100
0 2 4 6 8 10
Steady-state concentration, c

1. FIXED POINT ITERATION METHOD:


ALGORITHM:
In numerical Analysis, this method is used to find the fixed point iteration, more
specifically given function defines on the real values and a point x b in the domain of f,
thefixed point iteration is:
x n+1¿ g ¿n¿ n=0,1,2,3.... .
which gives rise to sequence x0, x1, x2 , ....., which is hoped to convert to a point x, if f
is continuous, then one can prove that the obtained ‘x’ is a fixed point of f, i.e.
f (x)= x

More generally the function f can be defined on any matrix space with values in that
same space.

MATLAB CODE:

TASK:

A mass balance for a pollutant in a well-mixed lake can be written as:

dc
v =w−Qc−kv √ c
dt

Given the parameter valuesas follows:


v=1× 106 m3
Q=1 ×10 5 m 3 / year
w=1 ×106 gm/ year
k =0.25 m0.5 / g0.5 / year
The equation takes the form:

25 √ c+ 10 c−100=0

Solve for the steady-state concentration, find the root using Fixed-point iteration method in
MATLAB.

PROGRAM:

%%
%%
clc
close all
clear all

f=@(x) 25*sqrt(x)+10*x-100 % Let steady-state concentration = x


g=@(x) 10-2.5*sqrt(x);
f(0)
f(5)
f(10)
fplot(f,[0,10])
xlabel('Steady-state concentration, c');
ylabel('f(c)');
title('FIXED-POINT ITERATION METHOD');
grid on
gtext('xr');

xa=0; % Initial guess

fprintf('i xa xr g_xr RE \n');

for i=1:45
xr=g(xa);
g_xr=10-2.5*sqrt(xr);
RE=abs((xr-xa)/xr)*100;
fprintf('\n%3d %15.7f %15.7f %15.7f %15.7f
%18.8f\n',i,xa,xr,g_xr,RE);
xa=xr;
end
fprintf('\n The root of given equation = %f \n',xr);

OUTPUT:

f=
@(x)25*sqrt(x)+10*x-100
ans =
-100

ans =
5.9017

ans =
79.0569

i xa xr g_xr RE
1 0.0000000 10.0000000 2.0943058 100.0000000

2 10.0000000 2.0943058 6.3820708 377.4851773

3 2.0943058 6.3820708 3.6843098 67.1845407

4 6.3820708 3.6843098 5.2013610 73.2229686

5 3.6843098 5.2013610 4.2983769 29.1664276

6 5.2013610 4.2983769 4.8168682 21.0075604

7 4.2983769 4.8168682 4.5131588 10.7640749

8 4.8168682 4.5131588 4.6889509 6.7294187

9 4.5131588 4.6889509 4.5865036 3.7490704

10 4.6889509 4.5865036 4.6459690 2.2336682

11 4.5865036 4.6459690 4.6113725 1.2799356

12 4.6459690 4.6113725 4.6314734 0.7502439

13 4.6113725 4.6314734 4.6197854 0.4340064

14 4.6314734 4.6197854 4.6265785 0.2529973

15 4.6197854 4.6265785 4.6226293 0.1468258

16 4.6265785 4.6226293 4.6249248 0.0854305

17 4.6226293 4.6249248 4.6235904 0.0496329

18 4.6249248 4.6235904 4.6243661 0.0288607

19 4.6235904 4.6243661 4.6239152 0.0167735

20 4.6243661 4.6239152 4.6241773 0.0097514


21 4.6239152 4.6241773 4.6240249 0.0056681

22 4.6241773 4.6240249 4.6241135 0.0032950

23 4.6240249 4.6241135 4.6240620 0.0019153

24 4.6241135 4.6240620 4.6240919 0.0011134

25 4.6240620 4.6240919 4.6240745 0.0006472

26 4.6240919 4.6240745 4.6240846 0.0003762

27 4.6240745 4.6240846 4.6240788 0.0002187

28 4.6240846 4.6240788 4.6240822 0.0001271

29 4.6240788 4.6240822 4.6240802 0.0000739

30 4.6240822 4.6240802 4.6240814 0.0000430

31 4.6240802 4.6240814 4.6240807 0.0000250

32 4.6240814 4.6240807 4.6240811 0.0000145

33 4.6240807 4.6240811 4.6240808 0.0000084

34 4.6240811 4.6240808 4.6240810 0.0000049

35 4.6240808 4.6240810 4.6240809 0.0000029

36 4.6240810 4.6240809 4.6240809 0.0000017

37 4.6240809 4.6240809 4.6240809 0.0000010

38 4.6240809 4.6240809 4.6240809 0.0000006

39 4.6240809 4.6240809 4.6240809 0.0000003

40 4.6240809 4.6240809 4.6240809 0.0000002

41 4.6240809 4.6240809 4.6240809 0.0000001

42 4.6240809 4.6240809 4.6240809 0.0000001

43 4.6240809 4.6240809 4.6240809 0.0000000

44 4.6240809 4.6240809 4.6240809 0.0000000

45 4.6240809 4.6240809 4.6240809 0.0000000

The root of given equation = 4.624081


GRAPH:

FIXED-POINT ITERATION METHOD

50
xr

0
f(c)

-50

-100
0 2 4 6 8 10
Steady-state concentration, c

You might also like