%demo of different built in approaches
clear
clc
%get dimension of the problem
n = input ('enter the dimension of the test problem')
A = 10*rand(n,n);
b = 10*rand(n,1);
%
%use inverse function
tic;
Ainv = inv(A);
x1 = Ainv*b;
t1=toc;
%
%use backslash directly
tic;
x2 = A\b;
t2 = toc;
%use LU factorization
tic;
[L U] = lu(A);
y3 = L\b;
x3 = U\y3;
t3 = toc;
%
%compare results
disp 'time for inv, \, LU'
[t1 t2 t3]
%[x1 x2 x3]

%[max(abs(x1-x2)) max(abs(x2-x2)) max(abs(x2-x3)) ]
