Jump to content

How to calculate matrix determinant? n*n or just 5*5.

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Daria Radchenko

Daria Radchenko

    Newbie

  • Members
  • Pip
  • 2 posts
Hi, everyone. I need to find matrix n*n (or 5*5) determinant. I have a function translated from Pascal, but there's INDEX OUT OF RANGE EXCEPTION. Could somebody help me?
Here's my code:
public static double DET(double[,] a, int n)

        {

            int i, j, k;

            double det = 0;

            for (i = 0; i < n - 1; i++)

            {

                for (j = i + 1; j < n; j++)

                {

                    det = a[j, i] / a[i, i];

                    for (k = i; k < n; k++)

                        a[j, k] = a[j, k] - det * a[i, k]; // Here's exception

                }

            }

            det = 1;

            for (i = 0; i < n; i++)

                det = det * a[i, i];

                return det;

        }
Thanx for any help.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Without seeing the code that is calling the above function, there's no way to know.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users