Question

Create a MATLAB Function for the half pipe volume problem. inputs length and OD outputs the...

Create a MATLAB Function for the half pipe volume problem.

inputs length and OD

outputs the volume in gals

%half_pipe.m
%calculates the volume of the cylinder and converts volume to gallons.

%Variables
%len=length
%od=outer diameter

len=input('Enter length of cylinder: ');
od=input('Enter outer diameter of cylinder: ');

%Calculate
id=0.8*od;
vol_outer=0.5*pi*(od/2)^2*len;
vol_inner=0.5*pi*(id/2)^2*len;

%Result
vol=vol_outer-vol_inner;
v_gals=vol/231;

%Output
fprintf('The volume of gallons is %1.4f gal \n ',v_gals)

Call the function from the command window to run.

Example for command window:

>>halfpipe_vol = halfpipe_volume_function(10,4)

[return variable] = function_name(argument variable 1, argument variable 2)

Homework Answers

Answer #2

I have copied the code below image. Save the file as function name. In this case half_pipe.m

Dont try to run the file from edition. Call the fuction in command window as shown

%half_pipe.m
%calculates the volume of the cylinder and converts volume to gallons.

%Variables: len=length, od=outer diameter
function [halfpipe_vol] = half_pipe(len,od);

%Calculate
id=0.8*od;
vol_outer=0.5*pi*(od/2)^2*len;
vol_inner=0.5*pi*(id/2)^2*len;

%Result
vol=vol_outer-vol_inner;
halfpipe_vol=vol/231;

%Output
fprintf('The volume in gallons is %1.4f \n ',halfpipe_vol);

end

answered by: anonymous
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions