Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The energy unit conversion problem solved in lecture using the MATLAB switch-cas

ID: 3862964 • Letter: T

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 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

Explanation / Answer

a) As given unit is ft-lbf so EJ = Ein/.738 and Ein = 738 so EJ = 1000

now EoutUnits is cal so Eout = EJ *.239 = 239

b) Ein = 239 EinUnit = CAL

As CAL is not recognised it will print "ERROR: Current units are typed incorrectly."

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote