Sei sulla pagina 1di 5

MATLAB ASSIGNMENT

Problem Statement
Calculate vapour composition of an ideal binary solution.

Data given
A=15.8062
B=2589.2
C=231.36
T=54 degree celsius
P=600 mm Hg

Concept used:
Antoine Equation- For Vapour-Liquid Equilibrium for ideal solutions
Ln (Pa)=A-(B/C+T)
where Pa= vapour pressure of A in mm Hg
T= Temperature Given (in degree celsius)
A,B,C are constants

Now, from Roult’s Law and Dalton’s Law,


y=x*Pa/P
where x=mole fraction in liquid phase
P= Total Pressure

Methods used for solving the problem:

1. Bisection Method

 The bisection method in mathematics is a root-finding method that


repeatedly bisects an interval and then selects a subinterval in which a root must lie hes the x-axis
at 0. Because the function never crosses the x-axis, however, no zero is found. For functions with no
valid zeros, fzero executes until Inf, NaN, or a complex value is detected.

for further processing. It is a very simple and robust method, but it is also relatively slow. Because of this,
it is often used to obtain a rough approximation to a solution which is then used as a starting point for
more rapidly converging methods. The method is also called the interval halving method, the binary
search method, or the dichotomy method.

The method is applicable for numerically solving the equation f(x) = 0 for the real variable x, where f is
a continuous function defined on an interval [a, b] and where f(a) and f(b) have opposite signs. In this
case a and b are said to bracket a root since, by the intermediate value theorem, the continuous function f
must have at least one root in the interval (a, b).
At each step the method divides the interval in two by computing the midpoint c = (a+b) / 2 of the interval
and the value of the function f(c) at that point. Unless c is itself a root (which is very unlikely, but possible)
there are now only two possibilities: either f(a) and f(c) have opposite signs and bracket a root, or f(c)
and f(b) have opposite signs and bracket a root. The method selects the subinterval that is guaranteed to
be a bracket as the new interval to be used in the next step. In this way an interval that contains a zero
of f is reduced in width by 50% at each step. The process is continued until the interval is sufficiently small.
Explicitly, if f(a) and f(c) have opposite signs, then the method sets c as the new value for b, and if f(b)
and f(c) have opposite signs then the method sets c as the new a. (If f(c)=0 then c may be taken as the
solution and the process stops.) In both cases, the new f(a) and f(b) have opposite signs, so the method is
applicable to this smaller interval.

2. Secant Method
In numerical analysis, the secant method is a root-finding algorithm that uses a succession
of roots of secant lines to better approximate a root of a function f. The secant method can be thought of
as a finite difference approximation of Newton's method.
The secant method is defined by the recurrence relation
Xn = Xn-1 – f(Xn-1)*( Xn-1 - Xn-2/(f(Xn-1) – f(Xn-2)))
As can be seen from the recurrence relation, the secant method requires two initial
values, x0 and x1, which should ideally be chosen to lie close to the root.

3. Newton Raphson Method


In numerical analysis, Newton's method (also known as the Newton–Raphson method), named after Isaac
Newton and Joseph Raphson, is a method for finding successively better approximations to the roots (or
zeroes) of a real-valued function. It is one example of a root-finding algorithm.
The Newton–Raphson method in one variable is implemented as follows:
The method starts with a function f defined over the real numbers x, the function's derivative f ′, and
an initial guess x0 for a root of the function f. If the function satisfies the assumptions made in the
derivation of the formula and the initial guess is close, then a better approximation x1 is
X1 = X0 – f(X0)/f’(X0)
Geometrically, (x1, 0) is the intersection of the x-axis and the tangent of the graph of f at (x0, f (x0)).
The process is repeated as
Xn = Xn-1 – f(Xn-1)/f’(Xn-1)
until a sufficiently accurate value is reached.

Solving Strategy
We first calculate the vapour pressure of the given liquid A by using any of the above methods
i.e. Bisection Method, Secant Method and Newton Raphson Method by using Antoine Equation.
In Bisection Method, we have to give two initial guesses.
In Secant Method, we have to give two initial guesses.
In Newton Raphson Method, we have to give only one initial guess.
We are using while loop here to check the condition of f(x3) not equal to zero.
Finally,we get the results in different number of iterations for different methods.
Now, we use the vapour pressure obtained to calculate the composition in vapour phase.
Matlab Codes for solvers

1. Bisection Method
clc
%Dtermintion of vapour compostion of given component in a solution%
%bisection Method%
A1=15.8062;B1=2589.2;C1=231.36;
T=54;%given tempearture in degree celsius
f=@(x) log(x)-A1+(B1/(C1+T));
x1=800; x2=900;
x_a=0.5;%mole fraction in liquid phase
P=600; %Total Pressure in mm Hg
i=1;
x3=(x1+x2)/2;
while(f(x3)~=0)
if(f(x1)*f(x2)<0.0)
x3=(x1+x2)/2;
if(f(x1)*f(x3)>0)
x1=x3;
else
x2=x3;
end
else
fprintf('Method Fails')
end
fprintf('%f %f \n',i,x3)
i=i+1;
end
y=x2*x_a/P;
fprintf('Composition in vapour is %f',y)

2. Secant Method
\%Dtermintion of vapour compostion of given component in a solution%
%Secant Method%
A1=15.8062;B1=2589.2;C1=231.36;
T=54;%given tempearture in degree celsius
f=@(x) log(x)-A1+(B1/(C1+T));
x0=600; x1=1000;
x_a=0.5;%mole fraction in liquid phase
P=600; %Total Pressure in mm Hg
i=1;
x2=x1-((f(x1)*(x1-x0))/(f(x1)-f(x0)));
while(f(x2)~=0)
x2=x1-((f(x1)*(x1-x0))/(f(x1)-f(x0)));
x0=x1;
x1=x2;
fprintf('%d %f \n' , i,x2)
i=i+1;
end
y=x2*x_a/P;
fprintf('Composition in vapour is %f',y)

3. Newton Raphson Method


clc
%Dtermintion of vapour compostion of given component in a solution%
%newton Raphson Method%
A1=15.8062;B1=2589.2;C1=231.36;
T=54;%given tempearture in degree celsius
f1=@(x) log(x)-A1+(B1/(C1+T));
x0=600;
x_a=0.5;%mole fraction in liquid phase
P=600; %Total Pressure in mm Hg
i=1;
f2=@(x) 1/x;
x1=x0-(f1(x0)/f2(x0));
while(f(x1)~=0)
x1=x0-(f1(x0)/f2(x0));
x0=x1;
fprintf('%d %f\n',i,x1);
i=i+1;
if(i>10)
break
end

end
y=x2*x_a/P;
fprintf('Composition in vapour is %f',y)

RESULTS AND COMPARITIVE STUDY:


Iteration Bisection Secant Newton
no. Raphson
1 850.0 862.961958 801.491559
2 825.0 837.279354 838.580164
3 837.5 839.481976 839.451231
4 843.75 839.451722 839.453683
5 840.625 839.451683
6 839.0625 839.451683
7 839.843750
8 839.453125
9 839.257813
10 839.355469
11 839.404297
12 839.428711
13 839.440918
14 839.447021
15 839.450073
16 839.451599
17 839.452362
18 839.451981
19 839.451790
20 839.451694
21 839.451647
22 839.451671
23 839.451683
Comparative Study

Chart Title
870
860
850
840
830
820
810
800
790
780
770
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

Bisection Secant Newton Raphson

Result and Discussion


After doing the comparative study of all the four method we infer that the Newton Raphson
method converges at the fastest rate.

Potrebbero piacerti anche