Function Handle Not Reading the Input I want Evaluated

Here is my code, I am having an issue with the function handle not reading the array defined for thplot. I am trying to get the inital plot of the function to make an estimated guess to evaluate my function at the built in fzeros function.
The error just says
error in line "fplot=f(thplot);"
why is it not able to evaluate the function f @ thplot?
%Feilder Throwing Ball to Catcher
%Define the function who's zeros we're looking for
format longthrew
Vo=30; % velocity initial in m/s
y=-.8; %Final height of the ball after throw (1.8m start to 1m finish)
x=90; %Distance the fielder threw the ball
g=9.81;%gravity
f= @(th) x*tan(th*pi/180)-(g*x^2/(2*Vo^2*(cos(th*pi/180)^2)))+y;
%plot the function to get idea for initial guess
thplot=[0:70];
fplot=f(thplot);
plot(thplot, fplot, 'b', thplot, fplot*0, 'r--')
xlabel('theta');
legend ('fplot', 'y=0');
xlabel(theta);
legend('F(theta)', 'y=0');

 采纳的回答

f= @(th) x.*tan(th.*pi/180)-(g.*x.^2./(2*Vo.^2.*(cos(th*pi/180).^2)))+y;
Some of the periods I added are not strictly necessary, but two of them are, a ./ and a .^

1 个评论

Ok great that solved the issue, appreciate the insight. I guess that would make sense as it is supposed to be element by element evaluation.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

产品

版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by