User defined function for volume of a fuel tank

Write a user-defined function (for the function name and argument, use V= Volfuel(y)) that gives the volume f fuel in the tank (in gallons) as a function of the height y (measured from the bottom). use the function to make a plot of the volume as a function of h for 0<=h<=40 in.
I have no clue where to even start on this problem. Any help would be awesome

4 Comments

Please explain, what you have done so far: Are you able to start Matlab and open an editor window? Did you read the documentation concerning "functions"? The Getting Started chapters are thought for beginners, especially when they do not have any clue yet.
I am not sure where to start it even on on paper. I also do not completely understand what it means to write a user-defined function. I have a decent understanding on how to implement problems in Matlab, but I just don't really understand this one.
Also whenever I try to run it in Matlab, it says either "undefined variable y" or "not enough input arguments." The code I am using is below.
function v= volfuel(y)
r=20 R=2*r
v=(pi*y*R^2+R*r+r^2)/3

Sign in to comment.

Answers (2)

Where to start? The same way you'd solve the problem on paper. Actually, it's probably a good idea to solve the problem on paper before writing any code. I've found that getting equations into simplest form on paper makes the equations easy to code, easy to troubleshoot typos, and simple equations make for efficient computing.
On your paper and on your computer screen, you'll probably start with the knowns, then there will be some math, then a plot.

1 Comment

I am not sure where to start it on paper. I also do not completely understand what it means to write a user-defined function

Sign in to comment.

Start with the shape of the tank. Is it a cylinder, sphere, or something else? If a cylinder for instance, is its long axis oriented vertically or horizontally? It’s essentially geometry from there.
The ‘user-defined function’ is a function you write to your specifications to do what you want it to do. See Function Basics for how functions work in MATLAB, and how to write them and use them.

4 Comments

The shape if a frustum of cone. The top radius=1.5r, the bottom radius=r. Height=H. The height in the middle, which I am taking to be the height of the fuel, is y.
Sounds like your user function might be able to start with
function [] = myfunction(bottomRadius,height)
topRadius = 1.5*bottomRadius;
% some math here
% some plotting here
end
It'll be a file of its own that you'll call myfunction.m. Then users will be able to simply type
myfunction(5,3)
to plot a cone of bottom radius = 5, height = 3.
Should the equation for volume be inside the brackets after function? I think this might be where I am having trouble.
The volume equation is v=(pi*y(R^2+R*r+r^2))/3
Anything inside those brackets is an output of the function. I left it empty, because I don't know exactly what you want as output. Here's an example of a function that lets a user enter any radius and color of a circle. It calculates the area of the circle and plots the circle using the circles function.
The output h is simply a handle for the plotted graphics object(s). It's not necessary to include h, but it gives users the ability to tinker with properties after plotting.
function [area,h] = circlearea(radius,color)
% math:
area = pi*radius.^2;
% make a plot:
h = circles(1,1,radius,'facecolor',color);
end

Sign in to comment.

Categories

Find more on Surfaces, Volumes, and Polygons in Help Center and File Exchange

Asked:

on 12 Apr 2015

Commented:

on 13 Apr 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!