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

functionhtankvolume

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?

Best Answer

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.
Related Question