A gas expands according to the law,. Initially, the
pressure is 100 kPa when the volume is 1 m^{3}. 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 deﬁnite integral to compute the work done (WD) as follows:

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

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

From the equation () and the equation () above, we can write:

By inserting P () in WD (), we get:

For MATLAB solution, we will consider P as a function of V () and WD (). Now, let us apply the three-step approach we have used earlier:

- Initialize variable volume as a row vector, from 1 with increments of 0.001 to 3:
`v=1:0.001:3;` - Declare variable pressure as
`p=100./v.^1.4;` - 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-ﬁle 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

- 瀏覽次數：1266