function Ball
% Coded by Nigel F. Reuel on 10.11.16
% Practice passing parameters in a root finding function - prob 6.21 from
% the book
% theta = angle at which the ball is thrown
% y = height at end of throw
g = 9.8; % m/s^2
v0 = 30; % m/s
x = 90; % m
yo = 1.8; %m
% Added after class, let's graph to see if it is what we expect. This will
% help us define our limits better:
G1 = @(theta) tan(theta)*x-g/(2*v0^2*cos(theta)^2)*x^2+yo;
fplot(G1,[.6 1])
% After moving the x-axis, this looks like the region of interest.
%
F1 = @(theta,y) tan(theta)*x-g/(2*v0^2*cos(theta)^2)*x^2+yo-y;
% Bisect method and Modified Secant method
y = 1; %m
xl = 0.8;
xu = .1;
xr = .85;
per = .01;
es = .1;
maxit = 20;
[root,~,~,~]= bisect(F1,xl,xu,es,maxit,y);
disp('The angle at which we should throw the ball according to bisect method is:')
root
[root,~,~]=modsecantmethod(F1,xr,per,es,maxit,y);
disp('The angle at which we should throw the ball according to modified secant method is:')
root
% From the plot we see there are two points that satisfy this equation (two
% roots) and I have set the inital guesses such that the methods here find
% both of the roots. I am not sure why we have two roots, as this physical
% problem should only have one solution, but at least we figured out why
% the parameter passing was NOT working.
end