How can I get this function to take vector inputs for x
古いコメントを表示
This function is to determine how much area a goat has to graze on when tied to a rope length x on the outside of a rectangular barn with sides length a and b. The rope can't be longer than a+b. It wont take vector inputs for x (to allow me to plot on a graph for a changing rope length) and I can't figure out why.
function[z] = goatgrazing(a,b,x)
if x <= a
if x <= b
z=(3/4).*pi.*(x).^2;
end
end
if x > a
if x <= b
z=(3/4).*pi.*(x).^2+(1/4).*pi.*(x-a).^2;
end
end
if x > b
if x <= a
z=(3/4).*pi.*(x).^2+(1/4).*pi.*(x-b).^2;
end
end
if x > b
if x > a
z = (3/4).*pi.*(x).^2+(1/4).*pi*(x-b).^2+(1/4).*pi.*(x).^2;
end
end
if x > a+b
error("These dimensions are not valid")
end
Also, any improvements to the code you could suggest would be appreciated.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Discrete Fourier and Cosine Transforms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!