% --- 2nd Micro-Exercise Solution Week 4 ---
clc; clear; close;
% Define the matrix
A = [2 1; 1 3];
b = [8; 13];

% Solve the system of equations Ax = b
x = A \ b;

% Display the solution
disp('The solution vector x is:');
disp(x);

x_inv = inv(A)*b;

disp('Verify using A^-1:');
disp(x_inv);

% Compare the difference
diff_norm = norm(x - x_inv);
fprintf('Difference between methods: %.3e\n', diff_norm);

% Check residuals
r = norm(A*x - b);
r_inv = norm(A*x_inv - b);

fprintf('Residual with A\\b : %.3e\n', r);
fprintf('Residual with inv(A)*b : %.3e\n', r_inv);