Question: The energy unit conversion problem solved in lecture using the MATLAB switch-case- end structure is shown below (with very few modifications): Sample Problem: Energy Unit
The energy unit conversion problem solved in lecture using the MATLAB switch-case- end structure is shown below (with very few modifications): Sample Problem: Energy Unit Conversion Ein = input('Enter the value of the energy (work) to be converted: '); EinUnits = input('Enter the current units (J, ft-lbf, or cal); ', 's'); EoutUnits = input ('Enter the new units (J, ft-lbf, or cal): ', 's') errorin = 0; errorout = 0; switch EinUnits case 'J' EJ = Bin; case ft-lbf' EJ = Ein/0.738; case 'cal' EJ = Ein/0.239; otherwise errorin = 1; end switch EoutUnits case J' Eout = EJ; case ft-lbf' Eout = EJ*0.738; case 'cal' Eout = EJ*0.239; otherwise errorout = 1; end if errorin disp('ERROR: Current units are typed incorrectly.') elseif errorout disp(ERROR: New units are typed incorrectly.') else fprintf('E = %g %s ', Eout, EoutUnits) end Imagine that you run the program above twice and you type the inputs shown below (in boldface) into the MATLAB Command Window. Write the output of the program to the Command Window in the spaces provided below (you don't need a calculator). a) Enter the value of the energy (work) to be converted: 738 Enter the current units (J, ft-lbf, or cal): ft-lbf Enter the new units (J, ft-lbf, or cal): cal b) Enter the value of the energy (work) to be converted: 239: Enter the current units (J, ft-lbf, or cal): CAL Enter the new units (J, ft-lbf, or oal): J
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
