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!