I want to write a Matlab function with 'h' and 'V' as vectors to determine the fluid volume of a tank, but I have a problem with the function. The error is in the body of the question. Can someone help me?

1 回表示 (過去 30 日間)
Yianni
Yianni 2014 年 10 月 9 日
回答済み: Roger Wohlwend 2014 年 10 月 9 日
function V = hstank2(h,r,hcl) r=0.40; hcl=1.2; Nh = 41; h=linspace(0,(2*r+hcl),Nh); V = zeros(size(h)); i= (h>=0)&&(h<=r); V(i)=(pi/3).*(r.^2*(3.*h(i)-r)-(h(i)-r).^3); i= (h>=r)&&(h<=r+hcl); V(i)=((2/3)*pi*r.^3)+(pi*r.^2.*(h(i)-r)); i= (h>=r+hcl)&&(h<=2*r+hcl); V(i)=((2/3)*pi*r.^3)+(pi*r.^2*hcl)+((pi/3)*... (3*r.^2.*(h(i)-r-hcl)-(h(i)-r-hcl).^3)); end
OUTPUT: Operands to the and && operators must be convertible to logical scalar values.
Error in hstank2 (line 5) i= (h>=0)&&(h<=r); V(i)=(pi/3).*(r.^2*(3.*h(i)-r)-(h(i)-r).^3);

回答 (1 件)

Roger Wohlwend
Roger Wohlwend 2014 年 10 月 9 日
Try & instead of &&.
i= (h>=0) & (h<=r);

カテゴリ

Help Center および File ExchangeFluid Dynamics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by