clc
close all
clear all

y0=2.1
x=18.2
h=1.82
g=9
v=15.2
t=0.3:0.0001:0.5
xi=0:0.1:x;
for i=1:1:length(xi)
    X=xi(i);
    for j=1:1:length(t)
        y(i,j)=X*tan(t(j))-0.5*(X*X*g)/(v*v*cos(t(j))*cos(t(j)))+h;
        yk=X*tan(t(j))-0.5*(X*X*g)/(v*v*cos(t(j))*cos(t(j)))+h;
        if yk>=2.099&yk<2.101
            tk=t(j);
            jk=j;
            xk=X;
        end
    end
end
surf(y)
shading interp
figure
plot(xi,y)
tk
xk
jk


% Utilizando o Método de Newton
% f(t)=x*tan(t)-0,5*x^2*g/v^2/(cos(x))^2)+h

% Aqui é importante fazer y(t)-y0
% 
% f(t)=x*tan(t)-0,5*x^2*g/v^2/(cos(x))^2)+h-y0

% f(t)=18,2*tan(x)-0,5*18,2^2*9/15,2^2/(cos(x)*cos(x))+1,82-2,1

% f'(t)=18,2*1/(cos(x)*cos(x))-0,5*18,2^2*9/15,2^2*2*1/(cos(x)*cos(x))*tan(x)

t0=0.4

for i=1:1:3
   xk=t0;
tk(i)=xk-(18.2*tan(xk)-0.5*18.2^2*9/15.2^2/(cos(xk)*cos(xk))+1.82-2.1)/...
    (18.2*1/(cos(xk)*cos(xk))-0.5*18.2^2*9/15.2^2*2*1/(cos(xk)*cos(xk))*tan(xk));
xk=tk(i);
end
format long
xk(end)









