You are here

Example 6.4

12 October, 2015 - 14:03

A gas expands according to the law,\textrm{PV}^{1.4}=c. Initially, the pressure is 100 kPa when the volume is 1 m3. Write a script to compute the work done by the gas in expanding to three times its original volume 1

Recall that PV diagrams can be used to estimate the net work performed by a thermodynamic cycle, see Wikipedia 2 or we can use definite integral to compute the work done (WD) as follows:

\textrm{WD}=\int pdv

If we rearrange the expression pressure as a function of volume, we get:

P=\frac{c}{V^{1.4}}

By considering the initial state, we can determine the value of c:

\begin{align*} c&=100\times 1^{1.4} \\ &= 100 \end{align*}

From the equation (P=\frac{c}{V^{1.4}}) and the equation (\begin{align*} c&=100\times 1^{1.4} \\ &= 100 \end{align*}) above, we can write:

p=\frac{100}{V^{1.4}}

By inserting P (p=\frac{100}{V^{1.4}}) in WD (\textrm{WD}=\int pdv), we get:

WD=\int_{1}^{3}\frac{100}{v^{1.4}}dv

For MATLAB solution, we will consider P as a function of V (p=\frac{100}{V^{1.4}}) and WD (WD=\int_{1}^{3}\frac{100}{v^{1.4}}dv). Now, let us apply the three-step approach we have used earlier:

  1. Initialize variable volume as a row vector, from 1 with increments of 0.001 to 3: v=1:0.001:3;
  2. Declare variable pressure as p=100./v.^1.4;
  3. Use the trapz function to calculate the work done, the output will be as follows:
    WorkDone=trapz(v,p)
WorkDone =
    88.9015

These steps can be combined in an m-file as follows:

    clc
disp('A gas expands according to the law, pv^1.4=C')
disp('Initial pressure is 100 kPa when the volume is 1 m3')
disp('Compute the work done by the gas in expanding')
disp('To three times its original volume')
disp(' ')                       % Display blank line
v=1:.001:3;         % Creating a row vector for volume, v
p=100./(v.^1.4);    % Computing pressure for volume
WorkDone=trapz(v,p) % Integrating p*dv over 1 to 3 cubic meters