I have typed this code to perform the LU factorization for A=xb when we are given matrix A and $x=(1,1,1)^T$
. My code is below
function q1()
% Define x_ex
x_ex = [1; 1; 1];
% Define epsilon for given k
for k = 0:9
epsilon = 10^(-k);
% Define matrix A
A = [2, -2, 0;epsilon - 2, 2, 0;0, -1, 3];
% formula to find vector b
b = A * x_ex;
% LU factorization
[L, U, P] = lu(A);
y = L (P * b);
x_ex = U y;
fprintf('For epsilon = 1e-%d:n', k);
fprintf('Vector b:n');
disp(b');
fprintf('For k=%d (epsilon=10^-%d):n', k, k);
disp('Permutation matrix P:');
disp(P);
end
end
However when I run this code P should return the identity and instead I am getting P = [1,0,0;0,0,1;0,1,0]. Is there an issue in my code that I am missing?
New contributor
helpmewmath is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.