Documentation ¶
Index ¶
- type Vector
- func (v0 Vector) Add(v1 Vector) Vector
- func (v0 Vector) Apply(mat matrix.Matrix) Vector
- func (v0 Vector) Clone() Vector
- func (v0 Vector) Dimension() int
- func (v0 Vector) Dual() Vector
- func (v0 Vector) Equals(v1 Vector, eps ...float64) bool
- func (v0 Vector) InnerProduct(v1 Vector) complex128
- func (v0 Vector) IsOrthogonal(v1 Vector) bool
- func (v0 Vector) IsUnit() bool
- func (v0 Vector) Mul(z complex128) Vector
- func (v0 Vector) Norm() complex128
- func (v0 Vector) OuterProduct(v1 Vector) matrix.Matrix
- func (v0 Vector) TensorProduct(v1 Vector) Vector
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Vector ¶
type Vector []complex128
Vector type manages complex number slice in vector
func New ¶
func New(z ...complex128) Vector
New creates a new vector with dimensions equal to the length of complex numbers passed as arguments.
func NewZero ¶
NewZero creates a new vector with all components set to zero.
Example ¶
package main import ( "fmt" "github.com/axamon/q/vector" ) func main() { v0 := vector.NewZero(4) fmt.Printf("%v\n", v0) }
Output: [(0+0i) (0+0i) (0+0i) (0+0i)]
func TensorProduct ¶
TensorProduct returns the vector resulting from multipling the all vectors passed as arguments together.
func TensorProductN ¶
TensorProductN returns the vector resulting from applying the tensor product beetween the vector and itself N times.
Example ¶
package main import ( "fmt" "github.com/axamon/q/vector" ) var v = vector.New( complex128(1+2i), complex128(3+4i), ) func main() { fmt.Println(vector.TensorProductN(v)) fmt.Println(vector.TensorProductN(v, 0)) fmt.Println(vector.TensorProductN(v, 1)) fmt.Println(vector.TensorProductN(v, 2)) fmt.Println(vector.TensorProductN(v, 3)) }
Output: [(1+2i) (3+4i)] [(1+2i) (3+4i)] [(1+2i) (3+4i)] [(-3+4i) (-5+10i) (-5+10i) (-7+24i)] [(-11-2i) (-25+0i) (-25+0i) (-55+10i) (-25+0i) (-55+10i) (-55+10i) (-117+44i)]
func (Vector) Add ¶
Add adds the vector to the first one.
Example ¶
package main import ( "fmt" "github.com/axamon/q/vector" ) var v = vector.New( complex128(1+2i), complex128(3+4i), ) func main() { result := v.Add(v) fmt.Printf("%v\n", result) }
Output: [(2+4i) (6+8i)]
func (Vector) Clone ¶
Clone clones the vector.
Example ¶
package main import ( "fmt" "github.com/axamon/q/vector" ) var v = vector.New( complex128(1+2i), complex128(3+4i), ) func main() { vCloned := v.Clone() fmt.Printf("%v\n", vCloned) }
Output: [(1+2i) (3+4i)]
func (Vector) Dimension ¶
Dimension returns the dimension of the vector
Example ¶
package main import ( "fmt" "github.com/axamon/q/vector" ) var v = vector.New( complex128(1+2i), complex128(3+4i), ) func main() { numOdDimensions := v.Dimension() fmt.Println(numOdDimensions) }
Output: 2
func (Vector) Dual ¶
Dual returns the complex conjugate of the vector.
Example ¶
package main import ( "fmt" "github.com/axamon/q/vector" ) var v = vector.New( complex128(1+2i), complex128(3+4i), ) func main() { vDual := v.Dual() fmt.Printf("%v\n", vDual) }
Output: [(1-2i) (3-4i)]
func (Vector) Equals ¶
Equals returns true if the two vectors are the same.
Example ¶
package main import ( "fmt" "github.com/axamon/q/vector" ) var v = vector.New( complex128(1+2i), complex128(3+4i), ) func main() { v3 := vector.NewZero(3) v2 := vector.NewZero(2) vCloned := v.Clone() fmt.Println(v.Equals(v3)) fmt.Println(v.Equals(v2)) fmt.Println(v.Equals(vCloned)) }
Output: false false true
func (Vector) InnerProduct ¶
func (v0 Vector) InnerProduct(v1 Vector) complex128
InnerProduct returns the complex number that results from applying the inner product between the two vectors.
func (Vector) IsOrthogonal ¶
IsOrthogonal returns true if the two vectors are othogonal to each other: their inner product is zero.
func (Vector) Mul ¶
func (v0 Vector) Mul(z complex128) Vector
Mul multiplies the vector by the complex number.
Example ¶
package main import ( "fmt" "github.com/axamon/q/vector" ) var v = vector.New( complex128(1+2i), complex128(3+4i), ) func main() { result := v.Mul(complex128(1 - 1i)) fmt.Printf("%v\n", result) result = v.Mul(complex128(5 + 2i)) fmt.Printf("%v\n", result) result = result.Mul(complex128(0 + 0i)) fmt.Printf("%v\n", result) }
Output: [(3+1i) (7+1i)] [(1+12i) (7+26i)] [(0+0i) (0+0i)]
func (Vector) Norm ¶
func (v0 Vector) Norm() complex128
Norm returns the normalized value of the vector elements.
func (Vector) OuterProduct ¶
OuterProduct returns the matrix that results from applying the outer product between the two vectors.
func (Vector) TensorProduct ¶
TensorProduct returns the vector that results from applying the tensor product between the two vectors.