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

One possible reason to write a script in MATLAB would be to facilitate a computa

ID: 2268011 • Letter: O

Question

One possible reason to write a script in MATLAB would be to facilitate a computation that you have to repeat on a regular basis. For example, suppose you work for a manufacturer that produces cylindrical fuel tanks. The design engineers typically tell you the dimensions in meters. Sometimes your construction engineers want to know the capacity of the tank in gallons. Now, it’s your turn.

Write a script named tank_capacity.m that a. asks for diameter and length of the tank in meters, and b. outputs the capacity in gallons.

Test your script for different values of diameter and length. The only output to the screen should be the requests for input and the final answer.

Explanation / Answer

Matlab Script:

function cap_gal = tank_capacity()
D = input('Please enter diameter in meters');%diameter
L = input('Please enter length in meters');%length
Vol = pi*((D^2)/4)*L;%volume
cap_gal = Vol*264.172;%capacity in gallons
end

command window log: