matrix

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2023 License: MIT Imports: 2 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matrix

type Matrix [][]complex128

Matrix is a matrix of complex128.

func AntiCommutator

func AntiCommutator(m, n Matrix) Matrix

AntiCommutator returns a matrix of {m,n}.

func Apply

func Apply(m ...Matrix) Matrix
Example
package main

import (
	"fmt"

	"github.com/itsubaki/q/math/matrix"
)

func main() {
	x := matrix.New(
		[]complex128{0, 1},
		[]complex128{1, 0},
	)

	for _, r := range matrix.Apply(x, x) {
		fmt.Println(r)
	}

}
Output:

[(1+0i) (0+0i)]
[(0+0i) (1+0i)]

func ApplyN

func ApplyN(m Matrix, n ...int) Matrix
Example
package main

import (
	"fmt"

	"github.com/itsubaki/q/math/matrix"
)

func main() {
	x := matrix.New(
		[]complex128{0, 1},
		[]complex128{1, 0},
	)

	for _, r := range matrix.ApplyN(x) {
		fmt.Println(r)
	}
	fmt.Println()

	for _, r := range matrix.ApplyN(x, 2) {
		fmt.Println(r)
	}

}
Output:

[(0+0i) (1+0i)]
[(1+0i) (0+0i)]

[(1+0i) (0+0i)]
[(0+0i) (1+0i)]

func Commutator

func Commutator(m, n Matrix) Matrix

Commutator returns a matrix of [m,n].

func Identity

func Identity(n, m int) Matrix

Identity returns a identity matrix.

func New

func New(v ...[]complex128) Matrix

New returns a new matrix of complex128.

func TensorProduct

func TensorProduct(m ...Matrix) Matrix
Example
package main

import (
	"fmt"

	"github.com/itsubaki/q/math/matrix"
)

func main() {
	x := matrix.New(
		[]complex128{0, 1},
		[]complex128{1, 0},
	)

	for _, r := range matrix.TensorProduct(x, x) {
		fmt.Println(r)
	}

}
Output:

[(0+0i) (0+0i) (0+0i) (1+0i)]
[(0+0i) (0+0i) (1+0i) (0+0i)]
[(0+0i) (1+0i) (0+0i) (0+0i)]
[(1+0i) (0+0i) (0+0i) (0+0i)]

func TensorProductN

func TensorProductN(m Matrix, n ...int) Matrix
Example
package main

import (
	"fmt"

	"github.com/itsubaki/q/math/matrix"
)

func main() {
	x := matrix.New(
		[]complex128{0, 1},
		[]complex128{1, 0},
	)

	for _, r := range matrix.TensorProductN(x, 2) {
		fmt.Println(r)
	}

}
Output:

[(0+0i) (0+0i) (0+0i) (1+0i)]
[(0+0i) (0+0i) (1+0i) (0+0i)]
[(0+0i) (1+0i) (0+0i) (0+0i)]
[(1+0i) (0+0i) (0+0i) (0+0i)]

func Zero

func Zero(n, m int) Matrix

Zero returns a zero matrix.

Example
package main

import (
	"fmt"

	"github.com/itsubaki/q/math/matrix"
)

func main() {
	fmt.Println(matrix.Zero(0, 0))
	fmt.Println(matrix.Zero(1, 1))
	fmt.Println(matrix.Zero(2, 2))

}
Output:

[]
[[(0+0i)]]
[[(0+0i) (0+0i)] [(0+0i) (0+0i)]]

func (Matrix) Add

func (m Matrix) Add(n Matrix) Matrix

Add returns a matrix of m+n.

func (Matrix) Apply

func (m Matrix) Apply(n Matrix) Matrix

Apply returns a matrix product of m and n.

Example
package main

import (
	"fmt"

	"github.com/itsubaki/q/math/matrix"
)

func main() {
	x := matrix.New(
		[]complex128{0, 1},
		[]complex128{1, 0},
	)

	fmt.Println("x:")
	for _, r := range x {
		fmt.Println(r)
	}

	fmt.Println("xx:")
	for _, r := range x.Apply(x) {
		fmt.Println(r)
	}

}
Output:

x:
[(0+0i) (1+0i)]
[(1+0i) (0+0i)]
xx:
[(1+0i) (0+0i)]
[(0+0i) (1+0i)]

func (Matrix) Clone

func (m Matrix) Clone() Matrix

Clone returns a clone of matrix.

func (Matrix) Conjugate

func (m Matrix) Conjugate() Matrix

Conjugate returns a conjugate matrix.

func (Matrix) Dagger

func (m Matrix) Dagger() Matrix

Dagger returns conjugate transpose matrix.

func (Matrix) Dimension

func (m Matrix) Dimension() (int, int)

Dimension returns a dimension of matrix.

func (Matrix) Equals

func (m Matrix) Equals(n Matrix, eps ...float64) bool

Equals returns true if m equals n. If eps is not given, epsilon.E13 is used.

func (Matrix) Imag

func (m Matrix) Imag() [][]float64

Imag returns a imaginary part of matrix.

Example
package main

import (
	"fmt"

	"github.com/itsubaki/q/math/matrix"
)

func main() {
	m := matrix.New(
		[]complex128{1 + 1i, 2 + 3i},
		[]complex128{4 + 5i, 6 + 7i},
	)

	for _, r := range m.Imag() {
		fmt.Println(r)
	}

}
Output:

[1 3]
[5 7]

func (Matrix) Inverse

func (m Matrix) Inverse() Matrix

Inverse returns a inverse matrix of m.

func (Matrix) IsHermite

func (m Matrix) IsHermite(eps ...float64) bool

IsHermitian returns true if m is hermitian matrix.

func (Matrix) IsSquare

func (m Matrix) IsSquare() bool

IsSquare returns true if m is square matrix.

func (Matrix) IsUnitary

func (m Matrix) IsUnitary(eps ...float64) bool

IsUnitary returns true if m is unitary matrix.

func (Matrix) Mul

func (m Matrix) Mul(z complex128) Matrix

Mul returns a matrix of z*m.

Example
package main

import (
	"fmt"

	"github.com/itsubaki/q/math/matrix"
)

func main() {
	m := matrix.New(
		[]complex128{0, 1 + 1i},
		[]complex128{1 + 1i, 0},
	)

	for _, r := range m.Mul(3i) {
		fmt.Println(r)
	}

}
Output:

[(0+0i) (-3+3i)]
[(-3+3i) (0+0i)]

func (Matrix) Real

func (m Matrix) Real() [][]float64

Real returns a real part of matrix.

Example
package main

import (
	"fmt"

	"github.com/itsubaki/q/math/matrix"
)

func main() {
	m := matrix.New(
		[]complex128{1 + 1i, 2 + 3i},
		[]complex128{4 + 5i, 6 + 7i},
	)

	for _, r := range m.Real() {
		fmt.Println(r)
	}

}
Output:

[1 2]
[4 6]

func (Matrix) Sub

func (m Matrix) Sub(n Matrix) Matrix

Sub returns a matrix of m-n.

func (Matrix) TensorProduct

func (m Matrix) TensorProduct(n Matrix) Matrix

TensorProduct returns a tensor product of m and n.

Example
package main

import (
	"fmt"

	"github.com/itsubaki/q/math/matrix"
)

func main() {
	x := matrix.New(
		[]complex128{0, 1},
		[]complex128{1, 0},
	)

	fmt.Println("x:")
	for _, r := range x {
		fmt.Println(r)
	}

	fmt.Println("xx:")
	for _, r := range x.TensorProduct(x) {
		fmt.Println(r)
	}

}
Output:

x:
[(0+0i) (1+0i)]
[(1+0i) (0+0i)]
xx:
[(0+0i) (0+0i) (0+0i) (1+0i)]
[(0+0i) (0+0i) (1+0i) (0+0i)]
[(0+0i) (1+0i) (0+0i) (0+0i)]
[(1+0i) (0+0i) (0+0i) (0+0i)]

func (Matrix) Trace

func (m Matrix) Trace() complex128

Trace returns a trace of matrix.

func (Matrix) Transpose

func (m Matrix) Transpose() Matrix

Transpose returns a transpose matrix.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL