func Inverse(matrix [][]float64) [][]float64 {
	determinant := Determinant(matrix)
	adj := Transpose(CofactorMatrix(MinorMatrix(matrix)))
	return MultiplyByScalar(adj, 1./determinant)
}
Calculates the inverse matrix
package matrix
import (
	"math/cmplx"
	"sort"
)
func column(matrix [][]float64, columnNumber int) (result []float64) {
	result = make([]float64, len(matrix))
	for ii := 0; ii < len(matrix); ii++ {
		for jj := 0; jj < len(matrix[0]); jj++ {
			result[ii] = matrix[ii][columnNumber]
		}
	}
	return
}
func Add(firstMatrix [][]float64, secondMatrix [][]float64) (result [][]float64) {
	result = make([][]float64, len(firstMatrix))
	for ii := 0; ii < len(firstMatrix); ii++ {
		result[ii] = make([]float64, len(firstMatrix[0]))
		for jj := 0; jj < len(firstMatrix[0]); jj++ {
			result[ii][jj] = firstMatrix[ii][jj] + secondMatrix[ii][jj]
		}
	}
	return
}
func Subtract(firstMatrix [][]float64, secondMatrix [][]float64) [][]float64 {
	secondMatrix = MultiplyByScalar(secondMatrix, -1.0)
	return Add(firstMatrix, secondMatrix)
}
func DotProduct(firstMatrix [][]float64, secondMatrix [][]float64) (result [][]float64) {
	result = make([][]float64, len(firstMatrix))
	for ii := 0; ii < len(firstMatrix); ii++ {
		result[ii] = make([]float64, len(secondMatrix[0]))
		for jj := 0; jj < len(secondMatrix[0]); jj++ {
			for kk := 0; kk < len(secondMatrix); kk++ {
				result[ii][jj] += firstMatrix[ii][kk] * secondMatrix[kk][jj]
			}
		}
	}
	return
}
func Determinant(matrix [][]float64) (result float64) {
	matrixLength := len(matrix)
	sums := make([]float64, matrixLength*2)
	for ii := 0; ii < len(sums); ii++ {
		sums[ii] = 1
	}
	for ii := 0; ii < matrixLength; ii++ {
		for jj := 0; jj < matrixLength; jj++ {
			if ii-jj < 0 {
				sums[matrixLength+ii-jj] *= matrix[ii][jj]
			} else {
				sums[ii-jj] *= matrix[ii][jj]
			}
			if ii+jj >= matrixLength {
				sums[ii+jj] *= matrix[ii][jj]
			} else {
				sums[ii+jj+matrixLength] *= matrix[ii][jj]
			}
		}
	}
	dim := matrixLength * 2
	if matrixLength == 2 {
		dim = 2
		matrixLength = 1
	}
	for ii := 0; ii < dim; ii++ {
		if ii >= matrixLength {
			result -= sums[ii]
		} else {
			result += sums[ii]
		}
	}
	return
}
func MinorMatrix(matrix [][]float64) (result [][]float64) {
	var (
		matrixLength int
	)
	matrixLength = len(matrix)
	result = make([][]float64, matrixLength)
	for ii := 0; ii < matrixLength; ii++ {
		result[ii] = make([]float64, matrixLength)
		for jj := 0; jj < matrixLength; jj++ {
			auxM := [][]float64{}
			for iik := 0; iik < matrixLength; iik++ {
				if iik != ii {
					auxR := []float64{}
					for jjk := 0; jjk < matrixLength; jjk++ {
						if jjk != jj {
							auxR = append(auxR, matrix[iik][jjk])
						}
					}
					auxM = append(auxM, auxR)
				}
			}
			result[ii][jj] = Determinant(auxM)
		}
	}
	return
}
func CofactorMatrix(matrix [][]float64) (result [][]float64) {
	result = make([][]float64, len(matrix))
	for ii := 0; ii < len(matrix); ii++ {
		result[ii] = make([]float64, len(matrix[0]))
		for jj := 0; jj < len(matrix[0]); jj++ {
			if (ii+jj)%2 == 0 {
				result[ii][jj] = matrix[ii][jj]
			} else {
				result[ii][jj] = -matrix[ii][jj]
			}
		}
	}
	return
}