Having problem with a function to define h acording to the volume!

1 view (last 30 days)
Im having problems with a function! I need to write a function that gives me the volume of fuel in the tank (The tank is a cylinder and two caps, V= pi*r^2*h + (4/3)*pi*r^3) as an function of the hight!
This is my code:
function V = Volfuel( H )
r=15;
h=40
A=pi*r^2*h
B=(4/3)*pi*r^3
V=(A+B)
plot(h,V)
xlabel('hojd'), ylabel('volym')
end
The value i have for h is "0<h<60" How shall i continue with this function? Anybody who can point me in the right direction?
  1 Comment
Image Analyst
Image Analyst on 24 Apr 2012
If the cap is a perfect sphere, and you have two of them, wouldn't you have two times (4/3)*pi*r^3? One spherical volume for each ball-shaped cap.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 24 Apr 2012
If h needs to be that vector (list of heights), then try this:
h=0:60;
A=pi*r^2 .* h
and the rest of the lines stay the same. That will make A (the only thing that depends on h) a function of h, and thus V will also then be a vector. Your plot will be plotting the vector V against the h values from 0 to 60.
By the way, your H input argument is not being used.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!