Numerical method for using Doolittle Method in MatLab I got
Numerical method for using Doolittle Method in MatLab.
I got this code for Doolittle Method, but I wonder that how can I get ann answer for this code process?
How can I insert inputs of it? please provide whole process that insert inputs and final results of it.
Here is the input matrix for Doolittle Method.
A = [1 2 1 1 0 0
2 6 4 2 1 0
3 14 12 3 4 1
1 2 1 2 6 12
0 2 2 -1 -3 -6
2 4 3 3 2 2];
b = [4 12 23 -21 15 3];
And here is Doolittle Method code that I got so far. Thanks.
function [L, U] = LU_Doolittle(A)
[n, m] = size(A); %The dimension of A
U = zeros(n, n); %Initialize U
L = eye(n); %Initialize L
for k = 1 : n %compute stage k
U(k, k) = A(k, k) - L(k, 1:k-1)*U(1:k-1, k);
for j = k+1 : n
U(k, j) = A(k, j) -L(k, 1:k-1)*U(1:k-1, j);
L(j, k) = (A(j, k)-L(j, 1:k-1)*U(1:k-1, k))/U(k, k);
end
end
Solution
function [L, U] = LU_Doolittle(A)
[n, m] = size(A); %The dimension of A
U = zeros(n, n); %Initialize U
L = eye(n); %Initialize L
for k = 1 : n %compute stage k
U(k, k) = A(k, k) - L(k, 1:k-1)*U(1:k-1, k);
for j = k+1 : n
U(k, j) = A(k, j) -L(k, 1:k-1)*U(1:k-1, j);
L(j, k) = (A(j, k)-L(j, 1:k-1)*U(1:k-1, k))/U(k, k);
end
end
