My determinant code isn't working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ama Kwaah

    My determinant code isn't working

    i have been trying to get the correct code for a 3x3 matrix and upon checking for information from the net, i realised it was almost like my code..i mean the logic was the same but when i run it, i get a random negative number which is far from the answer.
    Below is the code snippet for that portion:
    Code:
    double determinant =(x[0][0]*x[1][1]*x[2][2]) + (x[0][1]*x[1][2]*x[2][0]) + (x[0][2]*x[1][0]*x[2][1]) - 
    (x[0][0]*x[1][2]*x[2][1]) - (x[0][1]*x[1][0]*x[2][2]) -
           (x[0][2]*x[1][1]*x[2][0]);
    i hope i can get help from here
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Your calculation looks OK but you don't show your matrix.

    A random negative value usually means uninitialized variables.

    Comment

    Working...