Documentation ¶
Index ¶
- type Matrix
- func AntiCommutator(m, n Matrix) Matrix
- func Apply(m ...Matrix) Matrix
- func ApplyN(m Matrix, n ...int) Matrix
- func Commutator(m, n Matrix) Matrix
- func Identity(n, m int) Matrix
- func New(v ...[]complex128) Matrix
- func TensorProduct(m ...Matrix) Matrix
- func TensorProductN(m Matrix, n ...int) Matrix
- func Zero(n, m int) Matrix
- func (m Matrix) Add(n Matrix) Matrix
- func (m Matrix) Apply(n Matrix) Matrix
- func (m Matrix) Clone() Matrix
- func (m Matrix) Conjugate() Matrix
- func (m Matrix) Dagger() Matrix
- func (m Matrix) Dimension() (int, int)
- func (m Matrix) Equals(n Matrix, eps ...float64) bool
- func (m Matrix) Imag() [][]float64
- func (m Matrix) Inverse() Matrix
- func (m Matrix) IsHermite(eps ...float64) bool
- func (m Matrix) IsSquare() bool
- func (m Matrix) IsUnitary(eps ...float64) bool
- func (m Matrix) Mul(z complex128) Matrix
- func (m Matrix) Real() [][]float64
- func (m Matrix) Sub(n Matrix) Matrix
- func (m Matrix) TensorProduct(n Matrix) Matrix
- func (m Matrix) Trace() complex128
- func (m Matrix) Transpose() Matrix
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 ¶
AntiCommutator returns a matrix of {m,n}.
func Apply ¶
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 ¶
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 TensorProduct ¶
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 ¶
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 ¶
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) Apply ¶
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) Imag ¶
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) 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 ¶
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) TensorProduct ¶
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)]
Click to show internal directories.
Click to hide internal directories.