User defined function for volume of a fuel tank
Show older comments
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
Jan
on 12 Apr 2015
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.
john barnes
on 13 Apr 2015
john barnes
on 13 Apr 2015
Answers (2)
Chad Greene
on 12 Apr 2015
0 votes
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
john barnes
on 13 Apr 2015
Star Strider
on 13 Apr 2015
0 votes
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
john barnes
on 13 Apr 2015
Chad Greene
on 13 Apr 2015
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.
john barnes
on 13 Apr 2015
Chad Greene
on 13 Apr 2015
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
Categories
Find more on Surfaces, Volumes, and Polygons in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!