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

 채택된 답변

Walter Roberson
Walter Roberson 2021년 2월 11일
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

질문:

2021년 2월 11일

편집:

2021년 2월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by