Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. ElhamDecompose:= proc(A)
  2.  
  3. N:=LinearAlgebra[RowDimension](A);
  4. U:=A;
  5. P:=Matrix(N);
  6. for i from 1 to N do
  7. P[i,i]:=1;
  8. end do:
  9. L:=P;
  10.  
  11. for k from 1 to N-1 do
  12. s:=k;
  13. t:=abs(U(k,k));
  14.  
  15. for i from k+1 to N-1 do
  16. if abs(U[i,k]) > t then
  17. t:=abs(U[i,k]);
  18. s:= i;
  19. end if:
  20. end do:
  21.  
  22. i:=s:
  23.  
  24. p:=P[i,..]:
  25. P[i,..]:=P[k,..]:
  26. P[k,..]:=p:
  27.  
  28. u:=U[k,k..N]:
  29. U[k,k..N]:=U[i,k..N]:
  30. U[i,k..N]:=u:
  31.  
  32. l:=L[k,1..k-1]:
  33. L[k,1..k-1]:=L[i,1..k-1]:
  34. L[i,1..k-1]:=l:
  35.  
  36. for j from k+1 to N do
  37. L[j,k] := (U[j,k])/(U[k,k]):
  38. U[j,k..N] := U[j,k..N]-(L[j,k]*U[k,k..N]):
  39. end do:
  40. end do:
  41.  
  42. return (P,L,U):
  43.  
  44. end proc:
  45.  
  46. A:=<<1.0|3.0|5.0>,<2.0|4.0|7.0>,<1.0|1.0|0.0>>;
  47. ElhamDecompose(A);
  48. A:=<<1.0|3.0|5.0>,<2.0|4.0|7.0>,<1.0|1.0|0.0>>:
  49. LinearAlgebra:-LUDecomposition(B);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement