package main import ( "fmt" "github.com/gonum/matrix/mat64" ) func main() { // Create two matrices a := mat64.NewDense(2, 2, []float64{1, 2, 3, 4}) b := mat64.NewDense(2, 2, []float64{5, 6, 7, 8}) // Multiply the matrices c := mat64.NewDense(2, 2, nil) c.Mul(a, b) // Print the result fmt.Printf("Result: %v\n", mat64.Formatted(c)) }
package main import ( "fmt" "github.com/gonum/matrix/mat64" ) func main() { // Create a matrix and a scalar a := mat64.NewDense(2, 2, []float64{1, 2, 3, 4}) s := 2.0 // Multiply the matrix by the scalar b := mat64.NewDense(2, 2, nil) b.Scale(s, a) // Print the result fmt.Printf("Result: %v\n", mat64.Formatted(b)) }In this example, we create a matrix `a` with values `[[1, 2], [3, 4]]` and a scalar `s` with value `2`. We then multiply the matrix `a` by the scalar `s` using the Scale method and store the result in the `b` matrix. Finally, we print the result using the Formatted method. Package Library: gonum.matrix.mat64.