format long
format compact

xl = -10.;
xr = 0.;
np = 200;

x = linspace(xl, xr, np);
y = airy(x);

plot(x, y);
grid on;
xlabel('x');
ylabel('Ai(x)');
title('Airy function');
hold on

% By visual inspection conclude that the first (rightmost) negative root of
% Airy function is on the interval [-3., -1.], the second one is on the
% interval [-5., -3].

a1 = -3;
b1 = -1;

tol = 2*eps*abs(a1);

[x1b, n1b] = bisec(@airy, a1, b1, tol)
[x1s, n1s] = secant(@airy, a1, b1, tol)

airyprime = @(x) airy(1, x);  % use anonymous function for the derivative
[x1n, n1n] = newt(@airy, airyprime, a1, tol)

% are the roots consistent?
abs(x1b - x1s)
abs(x1b - x1n)

% plot just the root
plot(x1n, [0.], 'ro');

%

a2 = -5;
b2 = -3;

tol = 2*eps*abs(a2);

[x2b, n2b] = bisec(@airy, a2, b2, tol)
[x2s, n2s] = secant(@airy, a2, b2, tol)

[x2n, n2n] = newt(@airy, airyprime, a2, tol)

% are the roots consistent?
abs(x2b - x2s)
abs(x2b - x2n)

% plot just the root
plot(x2n, [0.], 'ro');
