Available under Creative Commons-ShareAlike 4.0 International License.
clc % Clear screen disp('This script computes the work done by') disp('The gas in expanding from volume v1 to v2') disp(' ') % Display blank line a=input('Enter the constant a: '); b=input('Enter the constant b: '); p_i=input('Enter the initial pressure [kPa]: '); v_i=input('Enter the initial volume [m3]: '); v_f=input('Enter the final volume [m3]: '); k=(p_i+(a/(v_i^2))*(v_i-b)); % Calculating constant k v=v_i:.001:v_f; % Creating a row vector for volume p=(k./(v-b))-(a./(v.^2)); % Computing pressure for volume WorkDone=trapz(v,p); % Integrating p*dv disp(' ') % Display blank line str = ['The work done by the gas in expanding from ', num2str(v_i),... ' m3 to ' num2str(v_f), ' m3 is ', num2str(WorkDone), ' kW.']; disp(str);
The output is:
This script computes the work done by The gas in expanding from volume v1 to v2 Enter the constant a: .01 Enter the constant b: .001 Enter the initial pressure [kPa]: 100 Enter the initial volume [m3]: 1 Enter the final volume [m3]: 2 The work done by the gas in expanding from 1 m3 to 2 m3 is 69.3667 kW.
- 瀏覽次數:1364