Documentation
¶
Index ¶
- func Eps(eps ...float64) float64
- type Matrix
- func (m0 Matrix) Add(m1 Matrix) Matrix
- func (m0 Matrix) Apply(m1 Matrix) Matrix
- func (m0 Matrix) Clone() Matrix
- func (m0 Matrix) Conjugate() Matrix
- func (m0 Matrix) Dagger() Matrix
- func (m0 Matrix) Dimension() (int, int)
- func (m0 Matrix) Equals(m1 Matrix, eps ...float64) bool
- func (m0 Matrix) Inverse() Matrix
- func (m0 Matrix) IsHermite(eps ...float64) bool
- func (m0 Matrix) IsUnitary(eps ...float64) bool
- func (m0 Matrix) Mul(z complex128) Matrix
- func (m0 Matrix) Sub(m1 Matrix) Matrix
- func (m0 Matrix) TensorProduct(m1 Matrix) Matrix
- func (m0 Matrix) Trace() complex128
- func (m0 Matrix) Transpose() Matrix
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Matrix ¶
type Matrix [][]complex128
Matrix type manages complex numbers in matrices.
func AntiCommutator ¶
func Commutator ¶
func TensorProduct ¶
TensorProduct implements the product for any number of matrices.
Example ¶
package main import ( "fmt" "github.com/axamon/q/matrix" ) func main() { m := matrix.New( []complex128{1 + 1i, 2 + 2i}, []complex128{3 + 3i, 0 + 0i}, ) mM := matrix.TensorProduct(m, m) for _, r := range mM { fmt.Println(r) } }
Output: [(0+2i) (0+4i) (0+4i) (0+8i)] [(0+6i) (0+0i) (0+12i) (0+0i)] [(0+6i) (0+12i) (0+0i) (0+0i)] [(0+18i) (0+0i) (0+0i) (0+0i)]
func TensorProductN ¶
TensorProductN returns a matrix whose elements are the product of the elements by themselves N times.
func (Matrix) Apply ¶
Apply returns a matrix that is the result of aplying the two matrices together.
func (Matrix) Conjugate ¶
Conjugate returns the matrix conjugated.
Example ¶
package main import ( "fmt" "github.com/axamon/q/matrix" ) var m = matrix.New( []complex128{1, 2, 3, 4}, []complex128{0, 1, 1 + 1i, 2 + 2i}, []complex128{0, 0, 1, 1}, []complex128{0, 0, 0, 1}, ) func main() { for _, r := range m { fmt.Println(r) } fmt.Println() mC := m.Conjugate() for _, r := range mC { fmt.Println(r) } }
Output: [(1+0i) (2+0i) (3+0i) (4+0i)] [(0+0i) (1+0i) (1+1i) (2+2i)] [(0+0i) (0+0i) (1+0i) (1+0i)] [(0+0i) (0+0i) (0+0i) (1+0i)] [(1-0i) (2-0i) (3-0i) (4-0i)] [(0-0i) (1-0i) (1-1i) (2-2i)] [(0-0i) (0-0i) (1-0i) (1-0i)] [(0-0i) (0-0i) (0-0i) (1-0i)]
func (Matrix) Dagger ¶
Dagger returns the matrix transposed and conjugated.
Example ¶
package main import ( "fmt" "github.com/axamon/q/matrix" ) var m = matrix.New( []complex128{1, 2, 3, 4}, []complex128{0, 1, 1 + 1i, 2 + 2i}, []complex128{0, 0, 1, 1}, []complex128{0, 0, 0, 1}, ) func main() { for _, r := range m { fmt.Println(r) } fmt.Println() mD := m.Dagger() for _, r := range mD { fmt.Println(r) } }
Output: [(1+0i) (2+0i) (3+0i) (4+0i)] [(0+0i) (1+0i) (1+1i) (2+2i)] [(0+0i) (0+0i) (1+0i) (1+0i)] [(0+0i) (0+0i) (0+0i) (1+0i)] [(1-0i) (0-0i) (0-0i) (0-0i)] [(2-0i) (1-0i) (0-0i) (0-0i)] [(3-0i) (1-1i) (1-0i) (0-0i)] [(4-0i) (2-2i) (1-0i) (1-0i)]
func (Matrix) IsHermite ¶
IsHermite returns true if the matrix is equal to its conjugated transposed.
Example ¶
package main import ( "fmt" "github.com/axamon/q/matrix" ) var m = matrix.New( []complex128{1, 2, 3, 4}, []complex128{0, 1, 1 + 1i, 2 + 2i}, []complex128{0, 0, 1, 1}, []complex128{0, 0, 0, 1}, ) func main() { mH := matrix.New( []complex128{2 + 0i, 2 + 1i, 4 + 2i}, []complex128{2 - 1i, 3 + 0i, 3 + 3i}, []complex128{4 - 2i, 3 - 3i, 3 + 0i}, ) fmt.Println(m.IsHermite()) fmt.Println(mH.IsHermite()) }
Output: false true
func (Matrix) IsUnitary ¶
IsUnitary returns true if the conjugate transpose of the matrix is equal to its inverse.
Example ¶
package main import ( "fmt" "github.com/axamon/q/matrix" ) var m = matrix.New( []complex128{1, 2, 3, 4}, []complex128{0, 1, 1 + 1i, 2 + 2i}, []complex128{0, 0, 1, 1}, []complex128{0, 0, 0, 1}, ) func main() { fmt.Println(m.IsUnitary()) mU := matrix.New( []complex128{1, 0, 0}, []complex128{0, 1, 0}, []complex128{0, 0, 1}, ) mU1 := matrix.New( []complex128{0.5 + 0.5i, 0.5 - 0.5i}, []complex128{0.4 - 0.5i, 0.5 + 0.5i}, ) fmt.Println(mU.IsUnitary()) fmt.Println(mU1.IsUnitary(0.1)) }
Output: false true true
func (Matrix) Mul ¶
func (m0 Matrix) Mul(z complex128) Matrix
Mul returns a matrix whose elements are the product of the argument by the original elements.
Example ¶
package main import ( "fmt" "github.com/axamon/q/matrix" ) var m = matrix.New( []complex128{1, 2, 3, 4}, []complex128{0, 1, 1 + 1i, 2 + 2i}, []complex128{0, 0, 1, 1}, []complex128{0, 0, 0, 1}, ) func main() { mMul := m.Mul(2 + 1i) for _, r := range mMul { fmt.Println(r) } }
Output: [(2+1i) (4+2i) (6+3i) (8+4i)] [(0+0i) (2+1i) (1+3i) (2+6i)] [(0+0i) (0+0i) (2+1i) (2+1i)] [(0+0i) (0+0i) (0+0i) (2+1i)]
func (Matrix) Sub ¶
Sub returns a matrix whose elements are the difference between the first matrix elements and the second matrix elements.
func (Matrix) TensorProduct ¶
TensorProduct returns a matrix whose elements are the tensor product of the two matrices.
Example ¶
package main import ( "fmt" "github.com/axamon/q/matrix" ) func main() { m := matrix.New( []complex128{1 + 1i, 2 + 2i}, []complex128{3 + 3i, 0 + 0i}, ) mTP := m.TensorProduct(m) for _, r := range mTP { fmt.Println(r) } }
Output: [(0+2i) (0+4i) (0+4i) (0+8i)] [(0+6i) (0+0i) (0+12i) (0+0i)] [(0+6i) (0+12i) (0+0i) (0+0i)] [(0+18i) (0+0i) (0+0i) (0+0i)]
func (Matrix) Trace ¶
func (m0 Matrix) Trace() complex128
Trace returns the sum of matrix diagonal components.
Example ¶
package main import ( "fmt" "github.com/axamon/q/matrix" ) var m = matrix.New( []complex128{1, 2, 3, 4}, []complex128{0, 1, 1 + 1i, 2 + 2i}, []complex128{0, 0, 1, 1}, []complex128{0, 0, 0, 1}, ) func main() { fmt.Println(m.Trace()) }
Output: (4+0i)
func (Matrix) Transpose ¶
Transpose returns the matrix transposed.
Example ¶
package main import ( "fmt" "github.com/axamon/q/matrix" ) var m = matrix.New( []complex128{1, 2, 3, 4}, []complex128{0, 1, 1 + 1i, 2 + 2i}, []complex128{0, 0, 1, 1}, []complex128{0, 0, 0, 1}, ) func main() { for _, r := range m { fmt.Println(r) } fmt.Println() mt := m.Transpose() for _, r := range mt { fmt.Println(r) } }
Output: [(1+0i) (2+0i) (3+0i) (4+0i)] [(0+0i) (1+0i) (1+1i) (2+2i)] [(0+0i) (0+0i) (1+0i) (1+0i)] [(0+0i) (0+0i) (0+0i) (1+0i)] [(1+0i) (0+0i) (0+0i) (0+0i)] [(2+0i) (1+0i) (0+0i) (0+0i)] [(3+0i) (1+1i) (1+0i) (0+0i)] [(4+0i) (2+2i) (1+0i) (1+0i)]