clear all
clc
close all
warning off
scrnsz = get(0, 'Screensize');

% create random tridiagonal test matrix 
% with subdiagonal a, diagonal b, and superdiagonal c
i = 1;
nvalues = [1000,2000,4000,8000,16000];
nvalues = [1000:1000:10000];
for n = nvalues
    a = rand(n-1,1);
    b = rand(n,1);
    c = rand(n-1,1);
    A = gallery('tridiag',a,b,c);

    % create random right-hand side 
    f = rand(n,1);

    tic
    x = A\f;
    tm(i) = toc;
    fprintf('Time for Matlab backslash solve with n = %d: %f seconds\n\n', n, tm(i))

    tic
    x = tridiag(a,b,c,f);
    tt(i) = toc;
    fprintf('Time for tridiag solve with n = %d: %f seconds\n\n', n, tt(i))

    if i > 1
        orderM(i) = log(tm(i-1)/tm(i))/log(nvalues(i-1)/nvalues(i));
        orderT(i) = log(tt(i-1)/tt(i))/log(nvalues(i-1)/nvalues(i));
    end
    i = i+1;
end

for j=2:i-1
    fprintf('Order estimates for    Matlab: %f,   tridiag: %f\n', orderM(j), orderT(j))
end
