function findif(n)
% finite differences method to solve fireworks problem
% n is number of divisions

global g te ye h;

g = 9.8;	% accel. of gravity, [m/sec^2]
te = 5;		% end time [sec]
ye = 40;	% end height [m]

h = te/n;

A(1,1) = 1;
b(1) = 0;	% y0 = 0

for i = 2:n
    A(i, i-1:i+1) = [1 -2 1];
    b(i) = -g*h^2;
end

A(n+1,n+1) = 1;
b(n+1) = ye;
b = b';		% make b into a column vector

y = A\b;
A
b'
y'

(y(2)-y(1))/h
(4*y(2)-y(3))/(2*h)	% best est. of initial velocity (parab thru 1st 3 pts)
hold off;
set(gca, 'FontSize', 16);	% for tick marks
plot(0:h:te, y, 'bo-', 'LineWidth',2);
xlabel('t', 'FontSize',20);
ylabel('y', 'FontSize',20);
title('Finite Difference Method', 'FontSize',20);
