Beruflich Dokumente
Kultur Dokumente
4
Solving Single Non-linear Equations Using Matlab
1. Objective:
The activity aims to solve non-linear equations using matlab functions and solve problems involving
equations of states.
3. Discussion:
At a specified temperature and pressure, solving equations of state allows us to find the specific
volume of a gaseous mixture of chemicals. It would be impossible to design a chemical plant without using
equations of state. By the knowledge of specific volume, one can determine the size, and thus, cost of the
plant, including the diameter of pipes, the horsepower of compressor and pumps, and the diameter of
distillation towers and chemical reactors. To design a plant without this important information is a very
challenging task.
To calculate the enthalpy and vapor-liquid properties of mixtures, determining the specific volume is
also the first step. Calculating this enthalpy is especially important when making energy balances to reduce
energy use and help the environment.
The ideal gas equation of state , which relates the pressure, temperature and specific volume, is a
familiar equation:
This equation is quite adequate when the pressure is low (such as one atmosphere). However, many
chemical processes take place at very high pressure. For example, ammonia is made at pressures of 220
atmospheres or more. Under these conditions, the ideal gas equation of state may not be a valid
representation of reality.
The first generalization of the ideal gas law was the van der Waal’s equation of state:
where b accounts for excluded volume ( a second molecule cannot use the same space already use by the
first molecule), and a accounts for the interaction force between two molecules. This extension is just a first
step, however, it will not be a good approximation at extremely high temperatures.
The Redlich-Kwong equation of state is a modification of van der Waal’s equation of state:
where
The Redlich-Kwong equation of state was modified further by Soave to give the Redlich-Kwong-
Soave equation of state ( called RK-Soave ), which is common one in process simulators:
The ω is the acentric factor, which is a tabulated quantity for many substances. Thus, the value of alpha can
be computed for each chemical and reduced temperature.
All these equations can be rearranged into a cubic function of specific volume. The form of the
Redlich-Kwong and Redlich-Kwong-Soave equation of state is
When given the temperature and pressure of a gaseous mixture, and the parameters a and b, then to find
the specific volume one would have to solve the cubic equation of state for specific volume.
For a pure component, the parameters a and b are determined from the critical temperature and
critical pressure, and possibly acentric factor. These are all tabulated quantities, and there are even
correlations for them in terms of vapor pressure and normal boiling point.
For mixtures, it is necessary to combine the values of a and b for each component according to the
composition of the gaseous mixture. Common mixing rules are shown below, in which the ys are the mole
fraction of each chemical in the vapor phase.
or
where
or
Thus, the only difference between the problem for a pure component and that for a mixture is in evaluation
of the parameters a and b.
4. Resources:
Matlab
5. Procedure:
1. a. To determine the value of x that will satisfy the equation:
In the parameter of fzero function, 0.5 is a value of x near to where the function crosses the x-axis.
It may also represent the best guess of the solution. Try other values. Use Table 1a for the
results.
clc
x = fzero(f, 0.5)
c. To create a function file and an m-file (filename: yourSurname_le06_p1c), the contents of the
files will be
f = cos(x) – 2*x^3;
end
For m-file:
clc
x = fzero(‘myfunction’,0.5)
Notice that the graph passes the x axis near x=3. To determine the value where the graph
Notice that the graph passes the x axis near x=6. To determine the value where the graph
Notice that the graph passes the x axis near x=9. To determine the value where the graph
b. Create an m-file (filename: yourSurname_le06_p2b), for Procedure 2a. Run it. Use Table 2b for
the results.
global P T n a b R
R=0 08206;
V = fzero(‘Waals’, Vest)
function f = Waals(x)
global P T n a b R
f = (P + n^2*a/x^2)*(x-n*b) – n*R*T;
end
In order for the m-file and function files to work correctly, the variables P, T, n, a, b, and R are
declared global. Run the m-file. Use Table 3 for the results.
4. To determine the specific volume of n-butane at 500 K and 18 atm using Redlich –Kwong equation
of state,
a. Create a function file with the temperature, pressure, and thermodynamic properties with the
following contents:
function y = specvol(v)
pc = 37.5; % Data from Perry’s Chemical Handbook { bar*1x10^5 Pa/bar*1 atm/101,325 Pa}
%Ness/Abbot
T = 500;
p = 18;
R = 0.08205;
aRK = 0.42748*(R*Tc)^2/pc
aRK = arK*(Tc/T)^0.5
bRK = 0.08664*(T*Tc/pc)
>>v = fzero(‘specvol’,0.2)
c. Use the command fsolve(), instead of fzero in 4b. Use Table 4 for the results.
5. To determine the molar volume for gaseous ammonia at a pressure P = 56 atm and a temperature
T = 450 K using the van der Waals equation of state for the following reduced pressures: P r =
0.0503144, 1, 2, 4, 10, and 20.
function x = waalsvol(vol)
global press a b R T
% filename: yourSurname_le6_p05b.m
clear all
format short e
global press a b R T
T = 450 ; % in K
a = 27/64*R^2*Tcrit^2/Pcrit;
b = R*Tcrit/(8*Pcrit);
% each pass in a loop varies the press and then the volume is calculated
for j = 1:6
press = Pcrit*Preduced(j)
volguess = R*T/press;
result(j,1) = Preduced(j);
result(j,2) = vol;
end
% end of calculation
disp(result)
6. Repeat Procedure 4 using five different gases to be assigned by your instructor. Use Perry’s
Chemical Handbook/2-138 Critical Constants. Create tables for the results.
7. Repeat Procedure 5 using the same five different gases assigned to you by your instructor. Create
tables for the results.
Course: CHE 508 Laboratory Exercise No.: 4
Group No.: Section: CH51FA2
Group Members: AQUINO, AIRAH DS Date Performed: 1-4-2019
Date Submitted: 1-4-2019
Instructor: ENGR. CRISPULO MARANAN
Table 1b. Solution of the non-linear equation , cos (x) – 2x 3 = 0, using an m-file
Contents of yourSurname_le06_p1b.m
clc
x = fzero(f, 0.5)
Matlab output:
x=
0.7214
Table 1c. Solution of the non-linear equation , cos (x) – 2x 3 = 0, using a function file and an m-file
Contents of the function file
function f = Aquino_lec06_p1c (x)
f = cos(x) - 2*x^3;
end
Contents of yourSurname_le06_p1c.m
clc
x = fzero('Aquino_lec06_p1c',0.5)
Matlab output:
x=
0.7214
2. Procedure 2
Figure 2a. Graph of 2sin(x) – x 1/2 + 2.5 from 0 to 4π
Matlab command:
fplot('2*sin(x) - sqrt(x) + 2.5', [0,4*pi])
Warning: fplot will not accept character vector or string inputs in a future release. Use fplot(@(x)2.*sin(x)-
sqrt(x)+2.5) instead.
> In fplot (line 107)
Matlab output:
3.4664
Matlab command(where the graph passes the x axis near x=6 ) :
>> x2 = fzero('2*sin(x) - sqrt(x) + 2.5',6)
Matlab output:
x2 =
6.2869
9.1585
Table 2b. Solution of the non-linear equation , 2sin(x) – x 1/2 + 2.5 =0, using an m-file
Contents of yourSurname_le06_p2b.m
clc
x = fzero(f,4*pi)
Matlab output:
x=
13.1659
Table 2c. Solution of the non-linear equation , 2sin(x) – x 1/2 + 2.5 =0, using a function file and an m-
file
Contents of the function file
function f = myfunction1 (x)
end
Contents of yourSurname_le06_p2c.m
clc
x = fzero('myfunction1',4*pi)
Matlab output:
f =
-1.0449
f =
-1.6904
f =
-0.3987
f =
-1.9368
f =
-0.1516
f =
-2.2482
f =
0.1612
f =
0.0244
f =
-8.5814e-04
f =
5.2399e-06
f =
1.1018e-09
f =
4.4409e-16
f =
-7.1054e-15
x =
13.1659
3. Procedure 3
global P T n a b R
f = (P + n^2*a/x^2)*(x-n*b) - n*R*T;
end
Contents of yourSurname_le06_p3.m
global P T n a b R
R=0.08206;
Vest = n*R*T/P;
V = fzero('Aquino__lec06_p3', Vest)
Matlab output:
V =
8.6613
4. Procedure 4
Table 4. Calculation of the specific volume of n-butane using
Redlich- kwong Equation of State having a function file
Contents of the function file:
function y = specvol(v)
%Ness/Abbot
T = 500;
p = 18;
R = 0.08205;
aRK = 0.42748*(R*Tc)^2/pc
aRK = arK*(Tc/T)^0.5
bRK = 0.08664*(T*Tc/pc)
13.8748
Matlab command using fsolve():
function y = specvol(v)
%Ness/Abbot
T = 500;
p = 18;
R = 0.08205;
aRK = 0.42748*(R*Tc)^2/pc
aRK = arK*(Tc/T)^0.5
bRK = 0.08664*(T*Tc/pc)
v = fsolve('specvol',0.2)
To use 'fsolve', the following product must be licensed, installed, and enabled:
Optimization Toolbox
5. Procedure 5
Table 5. Calculation of the volume of 2 moles of CO 2 using
Van der Waals Equation of State having a function file and an m-file
Contents of the function file
function x = waalsvol(vol)
global press a b R T
Contents of yourSurname_le06_p5b.m
% filename: Aquino_le6_p05b.m
format short e
global press a b R T
T = 450 ; % in K
a = 27/64*R^2*Tcrit^2/Pcrit;
b = R*Tcrit/(8*Pcrit);
% each pass in a loop varies the press and then the volume is
calculated
for j = 1:6
press = Pcrit*Preduced(j);
volguess = R*T/press;
result(j,1) = Preduced(j);
result(j,2) = vol;
end
% end of calculation
disp(result)
Matlab output:
Aquino_le6_p05b
Preduced Molar Vol
5.0314e-02 6.5171e+00
1.0000e+00 2.3351e-01
2.0000e+00 7.7268e-02
4.0000e+00 6.0654e-02
1.0000e+01 5.0875e-02
2.0000e+01 4.6175e-02
6. Procedure 6
Contents of the function file: Chloromethane
function y = svchloromethane(v)
%Ness/Abbot
T = 500;
p = 18;
R = 0.08205;
aRK = 0.42748*(R*Tc)^2/pc
aRK = arK*(Tc/T)^0.5
bRK = 0.08664*(T*Tc/pc)
Matlab output:
>> svchloromethane
aRK =
7.4646
%Ness/Abbot
T = 500;
p = 18;
R = 0.08205;
aRK = 0.42748*(R*Tc)^2/pc
aRK = arK*(Tc/T)^0.5
bRK = 0.08664*(T*Tc/pc)
Matlab output:
>> svchloropropane
aRK =
15.9075
Matlab output:
7. Procedure 7
<Create tables here … delete this message after doing so.>
7. Conclusion:
I therefore conclude that MATLAB can solve non-linear equations using matlab functions and solve
problems involving equations of states. It can solve the equations in an instant upon coding the function and
corresponding script it needs to execute the program.