Trying to calculate a volume by changing equation for volume for different variable parameter
3 ビュー (過去 30 日間)
古いコメントを表示
Hi, I am trying to calculate the volume of a tank given different values for radius and height of tank and liquid. My code keeps saying I have an undefined variable V. If someone could please help me figure out how to correct this I would greatly appreciate it. Thank you!
function Volume
h = 0:10
H = 10
r = 1
Vol = zeros([],1);
rad = zeros([],1);
Height = zeros([],1);
height = zeros([],1);
for i = 0:length(h)
if h <= r
V = pi.*h.^2.*(3.*r-h)./3
elseif (r <= h) & (h <= H-r)
V = 2.*pi.*r.^3./3+pi.*r.^2.*(h-r)
elseif ((H-r) <= h) & (h<=H)
V = 4.*pi.*r.^3./3+pi.*r.^2.*(H-2.*r)-pi.*(H-h).^2.*(3.*r-H+h)./3
end
Vol(i) = V ;
rad(i) = r ;
Height(i) = H;
height(i) = h;
end
disp('height volume')
disp([height;Vol])
0 件のコメント
回答 (1 件)
Christopher Wallace
2018 年 7 月 25 日
Hi Alison,
You're using the array 'h' in your if else statement which as written doesn't satisfy any of the conditions causing 'V' to never be defined.
If you're meaning to iterate over 'h' use:
h(i)
Best Regards,
Chris
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!