Advertisement
Guest User

LU

a guest
Oct 26th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. public Matrix LU(double eps = 1E-16)
  2. {
  3. if (!this.IsSquare())
  4. {
  5. throw new MException("Cant work with matrix that is not square");
  6. }
  7. int n = this.Cols;
  8. for (int i = 0; i < n - 1; i++)
  9. {
  10. for (int j = i + 1; j < n; j++)
  11. {
  12. if (Math.Abs((double)this[i, i]) < eps)
  13. {
  14. throw new MException("Division with 0!");
  15. }
  16. matrix[j, i] = (double)matrix[j, i] / matrix[i, i];
  17. for (int k = i + 1; k < n; k++)
  18. {
  19. matrix[j, k] -= (double)matrix[j, i] * matrix[i, k];
  20. }
  21. }
  22. }
  23. return this;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement