The implementation of numerical methods in MATLAB. I am looking for matrices L and U, the result is similar to the truth, but not at all what the built-in function gives (it’s not even in the rearranged lines). Tell me what I'm doing wrong?

Source matrix

A = [ 8.3 -8.9 -5.3; 9.5 5.2 -6.8; 7.1 -9.7 3.2 ]; b = [ 4.1; 3.9; 8.3 ]; [L,U] = Part12(A); disp(L); disp(U); 

and the function part12 itself

 function [ L, U ] = Part12( A ) %первый шаг L = zeros(3); U = zeros(3); L = diag(ones(1,3)); k=1; n=3; r=1; while 1 for j=r:n U(r,j) = A(r,j)-sum( L(r,k:(r-1))*U(k:(r-1),j) ); end if r==n break; end for i=(r+1:n) L(i,r) = (1/U(r,r))*( A(i,r) - sum(L(i,k:(r-1))*U(k:(r-1),r))); end r=r+1; end end 

I get (the first matrix is ​​L, the second is U):

enter image description here

built-in function gives the following result:

enter image description here

what am I doing wrong? The 15th and 23rd lines, where the amount was replaced by a separate variable, which was summed up with a cycle, everything is exactly the same, so there is hardly any problem with this, most likely a misunderstood algorithm. Who will tell? Thank you in advance!

    0