DAS_2024_1/zhimolostnova_anna_lab_6/util/matrix.go

37 lines
784 B
Go
Raw Permalink Normal View History

2024-10-22 20:30:00 +04:00
package util
import "math/rand"
// GetMinor Получение минора матрицы
func GetMinor(matrix [][]float64, col int) [][]float64 {
size := len(matrix)
minor := make([][]float64, size-1)
for i := range minor {
minor[i] = make([]float64, size-1)
}
for i := 1; i < size; i++ {
subCol := 0
for j := 0; j < size; j++ {
if j == col {
continue
}
minor[i-1][subCol] = matrix[i][j]
subCol++
}
}
return minor
}
// GenerateMatrix Генерация случайной матрицы размера size x size
func GenerateMatrix(size int) [][]float64 {
matrix := make([][]float64, size)
for i := range matrix {
matrix[i] = make([]float64, size)
for j := range matrix[i] {
matrix[i][j] = float64(rand.Intn(6))
}
}
return matrix
}