% Plots the time to compute both 
% inv(A)*b and A\b for random 
% square systems up to size N.

N = 300;

Times1 = [];
Times2 = [];

for n=1:N;
    A = rand(n,n);
    b = rand(n,1);
    tic; inv(A)*b; time1=toc;
    tic; A\b; time2=toc;
    Times1 = [Times1, time1];
    Times2 = [Times2, time2];
end

n = 1:N;
plot(n, Times1, 'r*', n, Times2, 'b*')
legend('Inverse', 'Backslash', 2)
title('\bf{Solving Systems of Linear Equations}')
xlabel('System Size')
ylabel('Time (sec)')