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');

 Accepted Answer

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 Comment

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.

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2020b

Community Treasure Hunt

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

Start Hunting!