In: Computer Science
Give me a working code in MATLAB for Crout Decomposition. The code must work totally fine and must break into 2 matrix L and U
It must be in MATLAB
The code used must use continue statement. If no continue statement is there in code it will be downvoted.
Answer only if you know or else i will dislike badly
MATLAB CODE which uses Crout's decompositon technique and also solves the system AX=B
clc;clear all
format long
a=[1 2 3;3 4 5;1 0 1];
b=[1;1;3];
[L,U]=CroutDecom(a);
y=ForwardSub(L,b);
x=BackwardSub(U,y)
function [L,U]=CroutDecom(A)
[r c]=size(A);
for(i=1:r)
U(i,i)=1;
L(i,1)=A(i,1);
if(i==1)
continue
end
U(1,i)=A(1,i)/(L(1,1));
end
for(i=2:r)
for(j=2:c)
L(i,j)=A(i,j)-L(i,1:j-1)*U(1:j-1,j);
if(j>=i+1)
U(i,j)=(A(i,j)-L(i,1:i-1)*U(1:i-1,j))./L(i,i);
end
end
end
end
function y=ForwardSub(a,b)
n=length(b);
y(1,1)=b(1)/a(1,1);
for i=2:n
y(i,1)=(b(i)-a(i,1:i-1)*y(1:i-1,1))./a(i,i);
end
end
function y=BackwardSub(a,b)
n=length(b);
y(n,1)=b(n)/a(n,n);
for i=n-1:-1:1
y(i,1)=(b(i)-a(i,i+1:n)*y(i+1:n,1))./a(i,i);
end
end