gonum / matrix

Matrix packages for the Go language [DEPRECATED]
446 stars 53 forks source link

Dense.Inverse incorrect result #397

Closed dis-sid closed 7 years ago

dis-sid commented 7 years ago

Hi,

First here is the code to reproduce the error :

func main() { m := mat64.NewDense(3, 3, []float64{ 2, -1, 1, -1, 2, -1, 1, 1, 2, }) mInv := mat64.NewDense(3, 3, make([]float64, 3*3)) mInv.Inverse(m) fmt.Println(mat64.Formatted(mInv)) }

The returned inverse matrix is :

[ [5/6] [1/6] [-1/2] [1/2] [1/2] [-1/2] [-1/6] [1/6] [1/2] ]

and that should be:

[ [0.75] [0.25] [-0.25] [ 0.25] [0.75] [0.25] [-0.25] [0.25] [0.75] ]

I don't have time to look at the code now, just wanted to notify it. Thanks

kortschak commented 7 years ago

As a trivial check, what do you get when you do p.Mul(m, mInv)?

dis-sid commented 7 years ago

Sorry typo error here, I've inputted 1 instead of -1 in the last row of the matrix ( [1, 1, 2] instead of [1, -1, 2]).

So it works, thank you, will be more vigilant next time.