You are on page 1of 32

Laboratory Exercise No.

6
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.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:
 Use matlab functions like fsolve() and fzero() in the solution of non-linear equations.
 Use function file together with an m-file to solve chemical engineering problem involving equation
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 alpha is particular to Redlich-Kwong equation of state.

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 parameter alpha is given a different formula,

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.

The Peng Robinson is another variation:

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:

cos (x) – 2x3= 0

Issue the command in MATLAB command window:

>>f=‘cos(x) – 2*x^3’

>>x = fzero(f, 0.5)

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.

b. To create an m-file (filename: yourSurname_le06_p1b), the contents will be

clc

f = ‘cos(x) – 2*x^3’; % suppress the output

x = fzero(f, 0.5)

Run the m-file. Use Table 1b for the results.

c. To create a function file and an m-file (filename: yourSurname_le06_p1c), the contents of the

files will be

For function file:

function f = myfunction (x)

% x is the input and f is the output

f = cos(x) – 2*x^3;

end

For m-file:

clc

x = fzero(‘myfunction’,0.5)

Run the m-file. Use Table 1c for the results.


2. a. To determine the graph of 2sin(x) – x1/2+ 2.5 from 0 to 4π. Issue the command in MATLAB
command window:

>>fplot('2*sin(x) - sqrt(x) + 2.5', [0,4*pi])

Use Figure 2a for the results.

Notice that the graph passes the x axis near x=3. To determine the value where the graph
crosses the x axis, issue the command:

>>x1 = fzero('2*sin(x) - sqrt(x) + 2.5',3)

Notice that the graph passes the x axis near x=6. To determine the value where the graph

crosses the x axis, issue the command:

>>x2 = fzero('2*sin(x) - sqrt(x) + 2.5',6)

Notice that the graph passes the x axis near x=9. To determine the value where the graph

crosses the x axis, issue the command:

>>x3 = fzero('2*sin(x) - sqrt(x) + 2.5',9)

Use Table 2a for the results.

b. Create an m-file (filename: yourSurname_le06_p2b), for Procedure 2a. Run it. Use Table 2b for

the results.

c. Create a function (myfunction1)and m-files (filename: yourSurname_le06_p2c),

for Procedure 2a.

Run the m-file.

Use Table 2c for the results.

3. To calculate the volume of 2 moles of CO2 ( a = 3.59 L3-atm/mol2, and b = 0.0427 L/mol) at
temperature of 50oC, and pressure of 6 atm using van der Waal’s equation.

( P + n2a/ V2) ( V – nb) = nRT

The contents of m-file ( filename: yourSurname_le06_p3) will be:

global P T n a b R

R=0 08206;
P=6; T = 323.2; n = 2; a = 3.59; b=0.047;

Vest = n*R*T/P;

V = fzero(‘Waals’, Vest)

The contents of function file will be:

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,

1. Create a function file with the temperature, pressure, and thermodynamic properties with

the following contents:

function y = specvol(v)

Tc = 425.2; % Data from Perry’s Chemical Handbook/2-138 Critical Constants

pc = 37.5; % Data from Perry’s Chemical Handbook { bar*1x10^5 Pa/bar*1 atm/101,325 Pa}

% Table B.1 Characteristic Properties of Pure Species / Intro ChE Thermo/Smith/Van

%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)
y = p*v^3 – R*T*v^2 + (aRK – p*bRK ^2 – R*T*bRK) *v –aRK*bRK;\

Save the file.

2. To evaluate the value of v , having a guess of v=0.2, in the matlab command window issue the
command;

>>v = fzero(‘specvol’,0.2)

Use Table 4 for the results.

3. 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.

a. The function file contains the following:


function x = waalsvol(vol)

global press a b R T

x = press*vol^3 – press*b*vol^2 – R*T*vol^2 + a*vol – a*b;

b. The m-file contains the following:

% filename: yourSurname_le6_p05b.m

clear all

format short e

global press a b R T

% set the constants

Pcrit = 111.3 ; % in atm

Tcrit = 405.5; % in Kelvin

R = 0.08206; % in li. atm/mole.K

T = 450 ; % in K

% the different values of pressure are stored in a single vector

Preduced = [ 0.0503144 1 2 4 10 20];


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;

% Use fzero or fsolve to calculate volume

vol = fzero(‘waalsvol’, volguess);

result(j,1) = Preduced(j);

result(j,2) = vol;

end

% end of calculation

disp(‘Preduced Molar Vol ‘)

disp(result)

Run the m-file. Use Table 5 for the results.

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 Computer Applications in ChE Laboratory Exercise No.: 6
Group No.: N/A Section: CH51FC1
Group Members: Date Performed: August 2, 2017
Percil, Queenie Rose I. Date Submitted:
Instructor:
Engr. Crispulo Maranan
6. Data and Results:
Procedure 1
Table 1a. Solution of the non-linear equation ,cos (x) – 2x3= 0, using fzero()
Matlab Command/s:
>>f = 'cos(x)-2*x^3'
>>x = fzero(f,0.5)
>>x = fzero(f,0.7)
Matlab output:
>>f='cos(x)-2*x^3'
f=
cos(x)-2*x^3

>>x = fzero(f,0.5)
x=
0.7214

>>x = fzero(f,0.7)
x=
0.7214

Table 1b. Solution of the non-linear equation , cos (x) – 2x3= 0, using an m-file
Contents of Percil_le06_p1b.m
clc
f ='cos(x)-2*x^3'; % suppress the output
x = fzero(f,0.5)
Matlab Command/s:
>> x = fzero(f,0.5)
Matlab output:
x=
0.7214
Table 1c. Solution of the non-linear equation , cos (x) – 2x3= 0, using a function file and an m-file
Contents of the function file
Function f = myfunctionPercil( x )
%Percil_le06_p1c
% x is the input and f is the output
f = cos(x)-2*x^3;
end
Contents of Percil_le06_p1c.m
%Percil_le06_p1c
clc
x = fzero('myfunctionPercil',0.5)
Matlab Command/s:
x = fzero('myfunctionPercil',0.5)
Matlab output:
x=

0.7214

Procedure 2
Figure 2a. Graph of 2sin(x) – x1/2+ 2.5 from 0 to 4π
Matlab command:
>>fplot('2*sin(x) - sqrt(x) + 2.5', [0,4*pi])
Matlab output:
Table 2a. Solution of 2sin(x) – x1/2+ 2.5 =0 using fzero()
Matlab command(where the graph passes the x axis near x=3)
>>x1 = fzero('2*sin(x) - sqrt(x) + 2.5',3)
Matlab output:
x1 =
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
Matlab command(where the graph passes the x axis near x=9) :
>>x3 = fzero('2*sin(x) - sqrt(x) + 2.5',9)
Matlab output:
x3 =
9.1585

Table 2b. Solution of the non-linear equation , 2sin(x) – x1/2+ 2.5 =0, using an m-file
Contents of Percil_le06_p2b.m
%Percil_le06_p2b
f = '2*sin(x) - sqrt(x) + 2.5';
x1 = fzero(f,3)
x2 = fzero(f,6)
x3 = fzero(f,9)
Matlab Command/s:
>>Percil_le06_p2b
Matlab output:
x1 =
3.4664

x2 =
6.2869

x3 =
9.1585
Table 2c. Solution of the non-linear equation , 2sin(x) – x1/2+ 2.5 =0,
using a function file and an m-file
Contents of the function file
function f = myfunctionPercil( x )
%Percil_le06_p2c
% x is the input and f is the output
f = 2*sin(x) - sqrt(x) + 2.5;
end
Contents of Percil_le06_p2c.m
%Percil_le06_p2c
clc
x1 = fzero('myfunctionPercil',3)
x2 = fzero('myfunctionPercil',6)
x3 = fzero('myfunctionPercil',9)
Matlab Command/s:

x1 =

0.7214

x2 =

0.7214

x3 =

0.7214

Matlab output:
x1 =

0.7214

x2 =

0.7214

x3 =

0.7214
Procedure 3

Table 3. Calculation of the volume of 2 moles of CO2 using


Van der Waals Equation of State having a function file and an m-file
Contents of the function file
function f = Waals( x )
%Percil_le06_p3a
global P T n a b R
f = (P + n^2 * a/x^2) * (x-n*b) - n*R*T;
end
Contents of Percil_le06_p3.m
%Percil_le06_p3a
global P T n a b R
R=0.08206;
P=6; T = 323.2; n = 2; a = 3.59; b=0.0427;
Vest = n*R*T/P;
V = fzero('Waals', Vest)
Matlab Command/s:
>>Percil_le06_p3a
Matlab output:
V=
8.6521

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 )
Tc = 425.2; % Data from Perry’s Chemical Handbook/2-138 Critical Constants
pc = 37.5; % Data from Perry’s Chemical Handbook { bar*1x10^5 Pa/bar*1 atm/101,325 Pa}
% Table B.1 Characteristic Properties of Pure Species / Intro ChE Thermo/Smith/Van
%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)
y = p*v^3-R*T*v^2+(aRK-p*bRK^2-R*T*bRK)*v-aRK*bRK;
end
Matlab command using fzero():
>> v = fzero('specvol',0.2)
Matlab output using fzero():
arK =
13.8748

aRK =
12.7950

bRK =
491.1910

v=
-0.0014
Matlab command using fsolve():
>>v = fsolve('specvol',0.2)
Matlab output using fsolve():
To use 'fsolve', the following product must be both licensed and installed:
Optimization Toolbox

Procedure 5
Table 5. Calculation of the volume of 2 moles of NH3 using
Van der Waals Equation of State having a function file and an m-file
Contents of the function file
function x = waals( vol )
%Percil_le6_p05a
global press a b R T
x = press*vol^3-press*b*vol^2-R*T*vol^2+a*vol-a*b;
end
Contents of Percil_le06_p05b.m
%filename: Percil_le6_p05b.m
clear all
format short e
global press a b R T
%set the constants
Pcrit = 111.3; % in atm
Tcrit = 405.5; % in Kelvin
R = 0.08206; % in li. atm/mole.K
T = 450; % in K
% the different values of pressure are stored in a single vector
Preduced = [ 0.0503144 1 2 4 10 20];
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;
% Use fzero or fsolve to calculate volume
vol = fzero('waalsvol', volguess);
result(j,1) = Preduced(j);
result(j,2) = vol;
end
% end of calculation
disp('Preduced Molar Vol')
disp(result)
Matlab Command/s:
>>Percil_le6_p05b
Matlab output:
press =

5.6000e+000

press =

1.1130e+002

press =

2.2260e+002
press =

4.4520e+002

press =

1113

press =

2226

Preduced Molar Vol


5.0314e-002 6.5171e+000
1.0000e+000 2.3351e-001
2.0000e+000 7.7268e-002
4.0000e+000 6.0654e-002
1.0000e+001 5.0875e-002
2.0000e+001 4.6175e-002

Procedure 6
Table 6a. Calculation of the specific volume of Hexane using
Redlich- kwong Equation of State having a function file
Contents of the function file:
function y = specvolHexane ( v )
Tc = 507.6; % Data from Perry’s Chemical Handbook/2-138 Critical Constants
pc = 3.025; % Data from Perry’s Chemical Handbook {MPa*(1 atm/0.101325 MPa)}
% Table B.1 Characteristic Properties of Pure Species / Intro ChE Thermo/Smith/Van
%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)
y = p*v^3-R*T*v^2+(aRK-p*bRK^2-R*T*bRK)*v-aRK*bRK;
end
Matlab command using fzero():
>> v = fzero('specvolHexane',0.2)
Matlab output using fzero():

arK =

2.4513e+002

aRK =

2.4698e+002

bRK =

7.2692e+003

v=

-1.8870e-003
Matlab command using fsolve():
v = fsolve('specvolHexane',0.2)
Matlab output using fsolve():

arK =

2.4513e+002

aRK =

2.4698e+002

bRK =

7.2692e+003

Equation solved.

fsolve completed because the vector of function values is near zero


as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>

v=

-1.8870e-003
Table 6b. Calculation of the specific volume of Hexanoic acid using
Redlich- kwong Equation of State having a function file
Contents of the function file:
function y = specvolHexanoicacid ( v )
Tc = 660.2; % Data from Perry’s Chemical Handbook/2-138 Critical Constants
pc = 3.308; % Data from Perry’s Chemical Handbook {MPa*(1 atm/0.101325 MPa)}
% Table B.1 Characteristic Properties of Pure Species / Intro ChE Thermo/Smith/Van
%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)
y = p*v^3-R*T*v^2+(aRK-p*bRK^2-R*T*bRK)*v-aRK*bRK;
end
Matlab command using fzero():
>> v = fzero('specvolHexanoicacid',0.2)
Matlab output using fzero():
arK =

3.7919e+002

aRK =

4.3572e+002

bRK =

8.6457e+003

v=

-2.7991e-003
Matlab command using fsolve():
v = fsolve('specvolHexanoicacid',0.2)
Matlab output using fsolve():
arK =

3.7919e+002

aRK =

4.3572e+002

bRK =

8.6457e+003

Equation solved, fsolve stalled.

fsolve stopped because the relative size of the current step is less than the
default value of the step size tolerance squared and the vector of function values
is near zero as measured by the default value of the function tolerance.

<stopping criteria details>

v=

-2.7991e-003

Table 6c. Calculation of the specific volume of 1-Hexanol using


Redlich- kwong Equation of State having a function file
Contents of the function file:
function y = specvol1Hexanol ( v )
Tc = 611.3; % Data from Perry’s Chemical Handbook/2-138 Critical Constants
pc = 3.446; % Data from Perry’s Chemical Handbook {MPa*(1 atm/0.101325 MPa)}
% Table B.1 Characteristic Properties of Pure Species / Intro ChE Thermo/Smith/Van
%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)
y = p*v^3-R*T*v^2+(aRK-p*bRK^2-R*T*bRK)*v-aRK*bRK;
end
Matlab command using fzero():
>> v = fzero('specvol1Hexanol',0.2)
Matlab output using fzero():
arK =

3.1208e+002

aRK =

3.4507e+002

bRK =

7.6847e+003

v=

-2.4939e-003
Matlab command using fsolve():
v = fsolve('specvol1Hexanol',0.2)
Matlab output using fsolve():
arK =

3.1208e+002

aRK =

3.4507e+002

bRK =

7.6847e+003

Equation solved.

fsolve completed because the vector of function values is near zero


as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>

v=

-2.4939e-003
Table 6d. Calculation of the specific volume of 2-Hexanol using
Redlich- kwong Equation of State having a function file
Contents of the function file:
function y = specvol2Hexanol ( v )
Tc = 585.3; % Data from Perry’s Chemical Handbook/2-138 Critical Constants
pc = 3.311; % Data from Perry’s Chemical Handbook {MPa*(1 atm/0.101325 MPa)}
% Table B.1 Characteristic Properties of Pure Species / Intro ChE Thermo/Smith/Van
%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)
y = p*v^3-R*T*v^2+(aRK-p*bRK^2-R*T*bRK)*v-aRK*bRK;
end
Matlab command using fzero():
>> v = fzero('specvol2Hexanol',0.2)
Matlab output using fzero():
arK =

2.9776e+002

aRK =

3.2216e+002

bRK =

7.6579e+003

v=

-2.3365e-003
Matlab command using fsolve():
v = fsolve('specvol2Hexanol',0.2)
Matlab output using fsolve():

arK =

2.9776e+002

aRK =

3.2216e+002

bRK =

7.6579e+003

Equation solved.

fsolve completed because the vector of function values is near zero


as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>

v=

-2.3365e-003

Table 6e. Calculation of the specific volume of 2-Hexanone using


Redlich- kwong Equation of State having a function file
Contents of the function file:
function y = specvol2Hexanone ( v )
Tc = 587.61; % Data from Perry’s Chemical Handbook/2-138 Critical Constants
pc = 3.287; % Data from Perry’s Chemical Handbook {MPa*(1 atm/0.101325 MPa)}
% Table B.1 Characteristic Properties of Pure Species / Intro ChE Thermo/Smith/Van
%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)
y = p*v^3-R*T*v^2+(aRK-p*bRK^2-R*T*bRK)*v-aRK*bRK;
end
Matlab command using fzero():
>> v = fzero('specvol2Hexanone',0.2)
Matlab output using fzero():
arK =

3.0231e+002

aRK =

3.2773e+002

bRK =

7.7442e+003

v=

-2.3504e-003
Matlab command using fsolve():
v = fsolve('specvol2Hexanone',0.2)
Matlab output using fsolve():
arK =

3.0231e+002

aRK =

3.2773e+002

bRK =

7.7442e+003

Equation solved.

fsolve completed because the vector of function values is near zero


as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>

v=

-2.3504e-003
Procedure 7

Table 7.a Calculation of the volume of 2 moles of Hexane using


Van der Waals Equation of State having a function file and an m-file
Contents of the function file
function x = waals7a( vol )
global press a b R T
x = press*vol^3-press*b*vol^2-R*T*vol^2+a*vol-a*b;
end
Contents of Percil_le06_p7a.m
clear all
format short e
global press a b R T
% set the constants
Pcrit = 29.85 ; % in atm
Tcrit = 507.6; % in Kelvin
R = 0.08206; % in li. atm/mole.K
T = 450 ; % in K
% the different values of pressure are stored in a single vector
Preduced = [ 0.0503144 1 2 4 10 20];
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;
% Use fzero or fsolve to calculate volume
vol = fzero('waals7a', volguess);
result(j,1) = Preduced(j);
result(j,2) = vol;
end
% end of calculation
disp('Preduced Molar Vol')
disp(result)
Matlab Command/s:
>>Percil_le06_p7a
Matlab output:
press =

1.5019e+000

press =

2.9850e+001

press =

5.9700e+001

press =

1.1940e+002

press =

2.9850e+002

press =

597

Preduced Molar Vol


5.0314e-002 2.4089e+001
1.0000e+000 2.8758e-001
2.0000e+000 2.6438e-001
4.0000e+000 2.4388e-001
1.0000e+001 2.2040e-001
2.0000e+001 2.0584e-001

Table 7.b Calculation of the volume of 2 moles of Hexanoic acid using


Van der Waals Equation of State having a function file and an m-file
Contents of the function file
function x = waals7b( vol )
global press a b R T
x = press*vol^3-press*b*vol^2-R*T*vol^2+a*vol-a*b;
end
Contents of Percil_le06_p7b.m
clear all
format short e
global press a b R T
% set the constants
Pcrit = 32.65; % in atm
Tcrit = 660.2; % in Kelvin
R = 0.08206; % in li. atm/mole.K
T = 450 ; % in K
% the different values of pressure are stored in a single vector
Preduced = [ 0.0503144 1 2 4 10 20];
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;
% Use fzero or fsolve to calculate volume
vol = fzero('waals7b', volguess);
result(j,1) = Preduced(j);
result(j,2) = vol;
end
% end of calculation
disp('Preduced Molar Vol')
disp(result)
Matlab Command/s:
>>Percil_le06_p7b
Matlab output:
press =

1.6428e+000
press =
3.2650e+001
press =
6.5300e+001
press =
1.3060e+002
press =
3.2650e+002
press =
653
Preduced Molar Vol
5.0314e-002 2.1629e+001
1.0000e+000 2.7794e-001
2.0000e+000 2.7082e-001
4.0000e+000 2.6121e-001
1.0000e+001 2.4619e-001
2.0000e+001 2.3497e-001

Table 7.c Calculation of the volume of 2 moles of 1-Hexanol using


Van der Waals Equation of State having a function file and an m-file
Contents of the function file
function x = waals7c( vol )
global press a b R T
x = press*vol^3-press*b*vol^2-R*T*vol^2+a*vol-a*b;
end
Contents of Percil_le06_p7c.m
clear all
format short e
global press a b R T
% set the constants
Pcrit = 34.01; % in atm
Tcrit = 611.3; % in Kelvin
R = 0.08206; % in li. atm/mole.K
T = 450 ; % in K
% the different values of pressure are stored in a single vector
Preduced = [ 0.0503144 1 2 4 10 20];
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;
% Use fzero or fsolve to calculate volume
vol = fzero('waals7c', volguess);
result(j,1) = Preduced(j);
result(j,2) = vol;
end
% end of calculation
disp('Preduced Molar Vol')
disp(result)
Matlab Command/s:
>>Percil_le06_p7c
Matlab output:

press =

1.7112e+000

press =

3.4010e+001

press =

6.8020e+001

press =

1.3604e+002

press =

3.4010e+002

press =

6.8020e+002

Preduced Molar Vol


5.0314e-002 2.0899e+001
1.0000e+000 2.5756e-001
2.0000e+000 2.4898e-001
4.0000e+000 2.3818e-001
1.0000e+001 2.2239e-001
2.0000e+001 2.1112e-001

Table 7.d Calculation of the volume of 2 moles of 2-Hexanol using


Van der Waals Equation of State having a function file and an m-file
Contents of the function file
function x = waals7d( vol )
global press a b R T
x = press*vol^3-press*b*vol^2-R*T*vol^2+a*vol-a*b;
end
Contents of Percil_le06_p7d.m
clear all
format short e
global press a b R T
% set the constants
Pcrit = 32.68; % in atm
Tcrit = 585.3; % in Kelvin
R = 0.08206; % in li. atm/mole.K
T = 450 ; % in K
% the different values of pressure are stored in a single vector
Preduced = [ 0.0503144 1 2 4 10 20];
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;
% Use fzero or fsolve to calculate volume
vol = fzero('waals7d', volguess);
result(j,1) = Preduced(j);
result(j,2) = vol;
end
% end of calculation
disp('Preduced Molar Vol')
disp(result)
Matlab Command/s:
>>Percil_le06_p7d
Matlab output:
press =

1.6443e+000

press =

3.2680e+001

press =

6.5360e+001

press =

1.3072e+002

press =

3.2680e+002
press =

6.5360e+002

Preduced Molar Vol


5.0314e-002 2.1819e+001
1.0000e+000 2.6399e-001
2.0000e+000 2.5359e-001
4.0000e+000 2.4116e-001
1.0000e+001 2.2379e-001
2.0000e+001 2.1173e-001

Table 7.e Calculation of the volume of 2 moles of 2-Hexanone using


Van der Waals Equation of State having a function file and an m-file
Contents of the function file
function x = waals7e( vol )
global press a b R T
x = press*vol^3-press*b*vol^2-R*T*vol^2+a*vol-a*b;
end
Contents of Percil_le06_p7e.m
clear all
format short e
global press a b R T
% set the constants
Pcrit = 32.44; % in atm
Tcrit = 587.61; % in Kelvin
R = 0.08206; % in li. atm/mole.K
T = 450 ; % in K
% the different values of pressure are stored in a single vector
Preduced = [ 0.0503144 1 2 4 10 20];
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;
% Use fzero or fsolve to calculate volume
vol = fzero('waals7e', volguess);
result(j,1) = Preduced(j);
result(j,2) = vol;
end
% end of calculation
disp('Preduced Molar Vol')
disp(result)
Matlab Command/s:
>>Percil_le06_p7e
Matlab output:

press =

1.6322e+000

press =

3.2440e+001

press =

6.4880e+001

press =

1.2976e+002

press =

3.2440e+002

press =

6.4880e+002

Preduced Molar Vol


5.0314e-002 2.1974e+001
1.0000e+000 2.6626e-001
2.0000e+000 2.5594e-001
4.0000e+000 2.4354e-001
1.0000e+001 2.2613e-001
2.0000e+001 2.1401e-001

7. Conclusion:
I therefore conclude that MATLAB can be used to compute and solve problems involving equations of state
by utilizing the built-in functions and familiarizing one’s self to the commands that are necessary for the
creation of scripts (m-file and function). The correct equations and constants must be correct to obtain a
correct solution to the problems that are to be solved.
8. Assessment (Rubric for Laboratory Performance):
TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES
RUBRIC FOR MODERN TOOL USAGE
(Engineering Programs)
Student Outcome (e): Use the techniques, skills, and modern engineering tools necessary for engineering
practice in complex engineering activities.
Program: Chemical Engineering Course: CHE 508 Section: CH51FC11stSem SY:2017-2018
Performance Unsatisfactory Developing Satisfactory Very Satisfactory Score
Indicators 1 2 3 4
1. Apply Fails to identify Identifies Identifies modern Recognizes the
appropriate any modern modern techniques and is benefits and
techniques, techniques to techniques but able to apply constraints of
skills, and perform fails to apply these in modern
modern discipline- these in performing engineering tools
tools to specific performing discipline-specific and shows
perform a engineering discipline- engineering task. intention to apply
discipline- task. specific them for
specific engineering engineering
engineering task. practice.
task.
2. Demonstrate Fails to apply Attempts to Shows ability to Shows ability to
skills in any modern apply modern apply fundamental apply the most
applying tools to solve tools but has procedures in appropriate and
different engineering difficulties to using modern effective modern
techniques problems. solve tools when solving tools to solve
and modern engineering engineering engineering
tools to problems. problems. problems.
solve
engineering
problems.
3. Recognize Does not Recognizes Recognizes the Recognizes the
the benefits recognize the some benefits benefits and need for benefits
and benefits and and constraints of and constraints of
constraints constraints of constraints of modern modern
of modern modern modern engineering tools engineering tools
engineering engineering engineering and shows and makes good
tools. tools. tools. intention to apply use of them for
them for engineering
engineering practice.
practice.
Total Score
Mean Score = (Total Score / 3)
Percentage Rating = (Total Score / 12) x 100%
Evaluated by: Engr. Crispulo G. Maranan August 2, 2017
Printed Name and Signature of Faculty Member Date

You might also like