function shootingMethod()
clear
clc
clf
hold on
global dt
axis([0 15*pi/2 -5 20])
dt = 0.05;

alpha = 2.0;
alphaold = 2.01;

fa = g(alpha);
faold = g(alphaold);
cnt = 1;
while abs(fa) > 1e-10
    fprintf('iteration %i g(%e) = %e\n',cnt,alpha,fa)
    newalpha = alpha - (fa/(fa-faold))*(alpha-alphaold);
    alphaold = alpha;
    alpha = newalpha;
    faold = fa;
    fa = g(alpha);
    if cnt > 10
        fprintf('Convergence not reached\n');
        break;
    end
    cnt = cnt + 1;
end
x = 0:0.1:15*pi/2;
plot(x,sin(x),'o')
fprintf('Final result: iteration %i g(%e) = %e\n',cnt,alpha,fa)
fprintf('error: %e\n', alpha-1)
fprintf('Done\n');
end

function y = g(alpha)
global dt
X = [0;alpha];
x = 0:dt:15*pi/2;
u = zeros(1,length(x));
v = zeros(1,length(x));


u(1) = 0;
v(1) = alpha;
for i = 2:length(x)
    u(i) = u(i-1) + dt*v(i-1);
    v(i) = v(i-1) + dt*(-sin(x(i)));
end
comet(x,u)
y = u(length(x))+1;
end
