Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Engineers should be familiar with the units and dimensions of various quantities in the common systems of units such as metric, imperial, SI, etc.

 

Engineers should be familiar with the units and dimensions of various quantities in the common systems of units such as metric, imperial, SI, etc. You are required to write a program in a function file HW6P2.m that converts either the pressure or the temperature from current units to the desired units. The function definition line will be function HW6P2 (S_PorT, Val, S_CU, S_DU) Where S_Port is a string indicating the type of the quantity ('P' or 'p' for pressure and 'T' or 't' for temperature). Val is the numerical value of a quantity in the current units. S_CU is a string of the current units and S_DU is a string of the desired units. The available units of the pressure is either 'kPa', 'bar', 'psi', 'atm' or 'torr'. Where (kPa is the kilo Pascal, psi is the pound per square inch, atm is atmosphere and torr is mm of mercury.) The available units for the temperature is either 'C', 'F', 'K', or 'R'. (C is for degree Celsius, F for degree Fahrenheit, K for Kelvin and R for Rankine.) 1. (4 pts) The function must use a main switch-case structure to switch between pressure conversion, temperature conversion or otherwise. If the string assigned to S_PorT as the function is called is any other character than ('P', 'p', 'T' or 't'), the function must call the MATLAB built-in error() function in the otherwise branch to display the message "The quantity entered is unrecognized, please enter P or p for pressure and T or t for temperature". See the help text of the error function by typing doc error at the command prompt. 2. If the string S_PorT is recognized the function proceed to the branch of either the pressure or the temperature of the main switch-case structure where the following is done in each of the temperature and the pressure branches: a. (7 pts) in a nested switch-case structure, if the string assigned to S_CU is recognized by the function, the function must convert the quantity entered from the current units to its value in a common units. For example, change everything to bar for pressure and everything to R for temperature. Otherwise, if S_CU is not recognized by the function, the function in the otherwise branch of th nested switch-case must call the error() function to display a message "Current units entered is unrecognized." b. (7 pts) in another switch-case structure nested in the same branch (P or T) as the previous one, if the string assigned to S_DU is recognized by the function, the function must convert the quantity in the common units calculated in the previous nested switch-case structure to its value in the desired units. Otherwise, if S_DU is not recognized by the function, the function in the otherwise branch of this nested switch-case must call the error() function to display a message "Error: The Units entered is not recognized." 3. (2 pts)After the end of the main switch-case structure, the function must use fprintf() to display the output in the format: >> HW6P2 ( 'P', 300, 'kPa', 'psi') 200 kPa 29 psi >> HW6P2 ('t', 300, 'K', 'F') 300 K 80.33 F 4. Conversions: a. 1 bar = 100 kPa = 14.5 psi = 750 torr = 0.9868 atm b. 1 R = 1 F +459.67 = 1 C (9/5) + 491.67 = 1 K (9/5) 5. Test your function for each of following cases: a. HW6P2('E', 300, 'K', 'F') b. HW6P2('P', 200, 'kPa', 'psi'), HW6P2('p', 20, 'psi', 'torr') c. HW6P2("T", 300, 'K', 'F'), HW6P2('t', 30, 'C', 'R') d. HW6P2('P', 300, 'K', 'F'), HW6P2("T", 200, 'kPa', 'psi') e. HW6P2('t', 300, 'kJ', 'F'), HW6P2('T', 300, 'F', 'mps') f. HW6P2('p', 300, 'PSI', 'psi'), HW6P2('p', 300, 'bar', 'gal')

Step by Step Solution

3.44 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

HW6P2m function HW6P2 SPorT Val SCU SDU Matlab function that converts either the pressure or the temperature from current units to the desired units Inputs SPorT string containing the unit for convers... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals of Heat and Mass Transfer

Authors: Incropera, Dewitt, Bergman, Lavine

6th Edition

978-0470055540, 471457280, 470881453, 470055545, 978-0470881453, 978-0471457282

More Books

Students also viewed these Mathematics questions