19 June 2014

Manual Dekomposition

I don't have this image. copyright wikipedia.org
Manual Dekomposition
Ini source codenya saat kuliah dulu

A=[4 3 5 1;9 5 2 8;7 1 6 3;1 4 7 8]
b=[52;63;72;98]
L=eye(4)
U=zeros(4)

U(1,:)= A(1,:)

for (i=2:4)
L(i,1)=A(i,1)/U(1,1)
end

for (baris=2:4)
    for(kolom=2:4)
        if (baris<=kolom)
            kurang=0;
            for(t=1:baris-1)
                kurang=kurang+L(baris,t)*U(t,kolom);
            end
            U(baris,kolom)=A(baris,kolom)-kurang;
        else
            for(t=1:kolom-1)
                kurang=kurang+L(baris,t)*U(t,kolom);
            end
            L(baris,kolom)=(A(baris,kolom)-kurang)/U(kolom,kolom);
        end
    end
end
disp(U);
disp(L);

y(1,1)=b(1,1);

for(p=2:4)
    kurang=0;
    for(w=1:p-1)
        kurang=kurang+L(p,w)*y(w,1);
    end
    y(p,1)=b(p,1)-kurang;
end
disp(y);

x(4,1)=y(4,1)/U(4,4)
for(z=3:-1:1)
    kurang=0;
    for(t=4:-1:z+1)
        kurang=kurang+U(z,t)*x(z,1);
    end
    x(z,1)=(y(z,1)-kurang)/U(z,z)
end
 disp(x)

0 komentar:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More