%% REQUIRED ROUTINE(s)% load me40matlab library% NOTE: plot(st), plot(pr) and thplot are not compatible with this ONLINE assignment system.% They can be used in your local computer by installing me40matlab library to your lo-% cal computer.if exist('me40matlab', 'dir') ~= 7unzip('me40matlab.zip', 'me40matlab');addpath(genpath('me40matlab'));% pwd % show current pathend
%% -GRADING SECTION (NOT editable)-
%% Part A% NOTE: define calcWork in the FUNCTION(s) SECTION at the end. Below is the pretest script:substance = 'water';prop = {'x''p'; 't''p'};val = {1 300; 200 300};units = {'''kPa'; 'C''kPa'};
[work,st,pr] = calcWork(substance,prop,val,units);
%% Part B% NOTE: finish the local functions for each subproblem in the FUNCTION(s) SECTIONfprintf('Part B \n');W = hw3partb; %kJfprintf('W = %g kJ \n',W);
% Part C% NOTE: finish the local functions for each subproblem in the FUNCTION(s) SECTIONfprintf('\nPart C\n');
fprintf('\n1) \n');[Ti,m_liq2,Tf,Wsys] = hw3partc1;fprintf('Initial temperature Ti = %g K \n',Ti);fprintf('Final temperature Tf = %g K \n',Tf);fprintf('Mass of liquid of state 2 m_liq2 = %g kg \n',m_liq2);fprintf('Total work Wsys = %g kJ \n',Wsys);
fprintf('\n2) \n');units = hw3partc2;fprintf('# of required units = %g \n',units);
fprintf('\n3) \n');[Pf_hand,Q_hand] = hw3partc3;fprintf('Final pressure Pf_hand = %g kPa \n',Pf_hand);fprintf('Transferred heat Q_hand = %g kJ \n',Q_hand);
fprintf('\n4) \n');[Pf_lib,Q_lib] = hw3partc4;fprintf('Final pressure Pf_lib = %g kPa \n',Pf_lib);fprintf('Transferred heat Q_lib = %g kJ \n',Q_lib);
%% -FUNCTION(s) SECTION-% edit the local functions that are called by the script above% NOTE: MATLAB local functions need to be at the end of the script. Please use the section% below for function definiton ONLY. You can write script ABOVE this section to check% your functions.
%% PART Afunction [work, st, pr]=calcWork(substance,prop,val,units)% Constant(s):R_universal = 8.314; %J/mol`Kst=0; pr=0; work=0;% Start writing your code under herest=0; pr=0; work=0;
end %calcWork
%% PART B% 1)function W = hw3partbW=0;% Start writing your code under hereW=0; %kJend %hw3partb
%% PART C% 1)function [Ti,m_liq2,Tf,Wsys] = hw3partc1Ti=0; m_liq2=0; Tf=0; Wsys=0;% Start writing your code under hereTi=0; %Km_liq2=0; %kgTf=0; %KWsys=0; %kJ% Please generate the P-V plot on your local computer. No submission is required for itend %hw3partc1
% 2)function units = hw3partc2% Calculates units and enter its numerical value below:% (No work needs to be shown. Feel free to use Matlab as a calculator.)units = 0;end %hw3partc2
% 3)function [Pf_hand,Q_hand] = hw3partc3Pf_hand=0; Q_hand=0;% Hand calculate Pf_hand & Q_hand and enter their numerical values below:% (No work needs to be shown. Feel free to use Matlab as a calculator.)Pf_hand=0; %kPaQ_hand=0; %kJend %hw3partc3
% 4)function [Pf_lib,Q_lib] = hw3partc4Pf_lib=0; Q_lib=0;% Start writing your code under herePf_lib=0; %kPaQ_lib=0; %kJend %hw3partc4
PART A Expand the MATLAB code that you developed for calculating reversible work (function calcWork) in the following way: If the working fluid is an ideal gas and the process is isothermal, calculate the work using the Ideal Gas Law. You can find out about the working fluid by issuing the following MATLAB commands: >> physicalState = st.phys; >> if strcmp(physicalState, 'ideal gas') ... where the first line returns a character string indicating the “physical state” such as 'liquid', 'sat liquid', 'twophase', 'sat vapor', 'vapor', or 'ideal gas', and the second line tests whether it is the one you are looking for ('ideal gas' here); or in a shorter form >> if st.phys == ″ideal gas″ ... If numerical integration is needed, use integral function from MATLAB. PART B A mass of 2.4 kg of air at 150 kPa and 12 °C is contained in a gas-tight, frictionless pistoncylinder device. The air is now compressed to a final pressure of 600 kPa. During the process, heat is transferred from the air such that the temperature inside the cylinder remains constant. Calculate the work during this process. Assume that air behaves as an ideal gas and the process is mechanically reversible. Solve by writing a function that calls calcWork. >> W = hw3partb • W [kJ] (double) – the work during this process PROBLEM SET 3 Page 2 of 3 ME40 Thermodynamics Spring 2024 M. Frenklach PART C 1) (Problem 4-120, Çengel & Boles, 9th Edition; Assume the process is mechanically reversible): A mass of 3 kg of a saturated liquid-vapor mixture of water is contained in a piston-cylinder device at 160 kPa. Initially, 1 kg of the water is in the liquid phase and the rest is in the vapor phase. Heat is now transferred to the water, and the piston, which is resting on a set of stops, starts moving when the pressure inside reaches 500 kPa. Heat transfer continues until the total volume increases by 20%, while the pressure maintains at 500 kPa. Determine (a) the initial and final temperatures, (b) the mass of liquid water when the piston first starts moving, and (c) the work done during this process. Also, on your local computer, observe the process on a P-v diagram. >> [Ti,m_liq2,Tf,Wsys] = hw3partc1 • Ti [K] (double) – initial temperature • m_liq2 [kg] (double) – mass of liquid of state 2 • Tf [K] (double) – final temperature • Wsys [kJ] (double) – total work done by the system 2) Do NOT use MATLAB me40matlab course package for this problem. A classroom that normally contains 40 people is to be air-conditioned with window airconditioning units of 5-kW cooling capacity. A person at rest may be assumed to dissipate heat at a rate of about 360 kJ/h. There are 10 lightbulbs in the room, each with a rating of 100 W. The rate of heat transfer to the classroom through the walls and the windows is estimated to be 15,000 kJ/h. If the room air is to be maintained at a constant temperature of 21 °C, determine the number of window air-conditioning units required. >> units = hw3partc2 • units(double) – the total number of air-conditioning units needed to cool the room. PROBLEM SET 3 Page 3 of 3 ME40 Thermodynamics Spring 2024 M. Frenklach 3) Assume H2 behaves as an ideal gas with constant specific heat. A 3 m3 rigid tank holds H2 at 250 kPa and 550 K. The gas is cooled down to 350 K. Without using me40matlab, determine the final pressure (kPa) and the heat transfer of the system (kJ). >> [Pf_hand,Q_hand] = hw3partc3 • Pf_hand [kPa] (double) – final pressure • Q_hand [kJ] (double) – heat transfer during the process 4) Repeat Part C.3 but this time with me40matlab. Observe the difference between this approach and the previous manual calculation. >> [Pf_lib,Q_lib] = hw3partc4 • Pf_lib [kPa] (double) – final pressure • Q_lib [kJ] (double) – heat transfer during the process