Sie sind auf Seite 1von 18

Laboratory Exercise No.

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.

2. Intended Learning Outcomes (ILOs):


The students shall be able to:
2.1 Use matlab functions like fsolve() and fzero() in the solution of non-linear equations.
2.2 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) – x 1/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 CO 2 ( 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,

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


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

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.

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

6. Data and Results:


1. Procedure 1
Table 1a. Solution of the non-linear equation , cos (x) – 2x 3 = 0, using fzero()
Matlab Command/s:
>>f ='cos(x) - 2*x^3'
>> x = fzero(f, 0.5)
Matlab output:
x=
0.7214

Table 1b. Solution of the non-linear equation , cos (x) – 2x 3 = 0, using an m-file
Contents of yourSurname_le06_p1b.m
clc

f = 'cos(x) - 2*x^3'; % suppress the output

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)

% x is the input and f is the output

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:

Table 2a. Solution of 2sin(x) – x 1/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) – x 1/2 + 2.5 =0, using an m-file
Contents of yourSurname_le06_p2b.m
clc

f = '2*sin(x) - sqrt(x) + 2.5'; % suppress the output

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)

% x is the input and f is the output

f = 2*sin(x) - sqrt(x) + 2.5;

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

Table 3. 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 f = Aquino__lec06_p3(x)

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;

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

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)

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;

Matlab command using fzero():


v = fzero('specvol',0.2)
Matlab output using fzero():
aRK =

13.8748
Matlab command using fsolve():
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;

Matlab output using fsolve():

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

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

Contents of yourSurname_le06_p5b.m
% filename: Aquino_le6_p05b.m

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 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)

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


Constants

pc = 66.8; % 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;

Matlab output:
>> svchloromethane

aRK =
7.4646

Contents of the function file: 1-Chloropropane


function y = svchloropropane(v)

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


Constants

pc = 45.8; % 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;

Matlab output:
>> svchloropropane

aRK =

15.9075

Contents of the function file:

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.

Das könnte Ihnen auch gefallen