Вы находитесь на странице: 1из 4

CAPE2060 Assignment

Numerical methods for solving equations of state


This workshop is designed to give you experience of implementing three different numerical
techniques in Matlab. The first numerical technique in Newton’s method for finding the roots
of an equation of the form f(x) = 0. The second numerical technique is the Trapezium Rule to
evaluate a definite integral. The third numerical technique requires you to implement an
optimisation loop similar to the ‘goal seek’ function in Microsoft Excel. You should also refer
to the slides from the lecture during the tutorial session. These are available on the VLE under
the Learning Resources tab.

To take account of deviations from ideal behaviour by real gases a modified van der Waals
Equation of State can be employed, given as:

8𝑇𝑅 27
𝑃𝑅 = − Equation 1
8𝜙−1 64𝜙2

Where 𝑃𝑅 is the reduced gas pressure, 𝑇𝑅 is the reduced absolute temperature and 𝜙 is a
corrected molar volume.

Tasks

1. Write Equation 1 as a Matlab function FOR reduced temperatures of 0.85, 0.9, 0.95
and 1, calculate the reduced pressure for molar volumes in the range of 0.15 to 1.75
with an interval of 0.02. Plot the four pressure isotherms (pressure on the y-axis,
molar volume on the x-axis) on a logarithmic y-scale using different scatter
symbols for each profile. Show a fifth dashed line profile at a constant reduced
pressure of 0.6 and label each of the 5 profiles in a legend.
2. Consider the isotherm at a reduced temperature of 0.9. As can be seen from your plot,
three different values of ϕ correspond to the same reduced pressure of 0.6. It is
possible to use Newton’s Method, described in the lecture slides, to find the three
values of 𝜙 for which the reduced pressure is 0.6. First, write a rearranged
expression for the van der Waals equation of state in the form 𝒇(𝝓) = 𝟎. Second,
𝒅𝑷
write an expression for the first derivative of pressure, 𝒅𝝓 = 𝒇(𝝓), and create a
new Matlab function to calculate the derivative of pressure for a given molar volume
and temperature.
3. For a function 𝑓(𝑥), Newton’s method uses the function and its derivative to solve for
the roots of the function, i.e. the values of 𝜙 such that 𝑓(𝜙) = 0 in this instance. Draw
a block diagram to demonstrate the processing steps required to iterate to within
a defined tolerance of an exact root using Newton’s method (see Figure 1 for
reference). Write a Matlab function which uses your Newton’s method algorithm to
iterate towards each of the three roots from initial estimates based on observations
from your graph in part 1. Your function should contain a ‘loop’ which updates the
estimated root until the function falls below a given tolerance (tol), 𝑓(𝜙) < 𝑡𝑜𝑙. How
many iterations of the loop are required to converge to within your chosen tolerance?
Comment on the physical significance (property of a gas) of each of these three
roots you have found.
4. Append some additional lines of code to the bottom of the function in part 3 to calculate
(1) the area between the first and second root and (2) the area between the second
and third root. In each case define a linearly spaced vector 50 values in length between
the lower and upper root to form a discretised dataset and approximate the areas
between the roots using the trapezium rule. Matlab has an in-built function to
numerically solve integrals with the trapezium rule called ‘trapz’, use the ‘help’ function
in Matlab to understand the syntax of this function.
5. For a given pressure isotherm, a characteristic reduced pressure will exist whereby
the area between the first and second root will be the same in magnitude as that
between the second and third root. The ‘block diagram’ in Figure 1 describes a basic
‘goal seek’ algorithm to iterate towards this solution and stop when the sum of the two
areas falls below a defined tolerance. Write a Matlab script based on this diagram to
solve for the characteristic reduced pressure for a reduced temperature of 0.9. How
many iterations of the goal seek loop are required to converge within tolerances
of 10-3 and 10-5? Create a plot (on linear axes) of the pressure isotherm between
the smallest and largest root along with a linear profile at the characteristic
reduced pressure, label the two profiles accordingly in a clear legend.

Submission

On no more than 3 sides of A4, submit a report including:


(1) the two equations requested in part 2
(2) the two figures requested in parts 1 and 5 with clear captions, axis labels and legends
(3) a block diagram illustrating your Newton’s method algorithm
(4) a paragraph which comments on the physical significance of the roots of the pressure
isotherm
(5) a paragraph discussing the impact of the chosen tolerance on the number of loop iterations
required and the run time to converge the ‘root finder’ algorithm in part 2, and the goal seek
algorithm in part 5
(6) a paragraph describing the numerical techniques you have used.

Overleaf, you should include four (clearly commented) Matlab codes in appendices as follows:

Appendix A – the function to calculate pressure using the modified van der Waals equation
Appendix B – the function to calculate the derivative of pressure with respect to molar volume
Appendix C – the function using the Newton-Raphson method to identify three roots and the
areas between each pair of roots using the trapezium rule
Appendix D – a Matlab script which includes the loop to ‘goal seek’ the characteristic pressure
and create the two figures included in your submission.
Calculate isotherm roots

Calculate areas between


roots and 𝑃𝑅

Is the sum of the areas


Yes smaller in magnitude
than the defined
tolerance?

Accept 𝑷𝑹 as the
characteristic pressure
No

Is the magnitude of the


area between roots 1 and
2 greater than that
between roots 2 and 3?

Yes No

Decrease 𝑃𝑅 by 0.1% Increase 𝑃𝑅 by 0.1%

Replace initial roots


estimate with roots
calculated in step (1)

Figure 1: Block diagram of a goal seek algorithm to find the characteristic pressure of a pressure
isotherm whereby the areas between two pairs of its roots are equal in magnitude

Вам также может понравиться