vector

package
v0.0.0-...-c1fb209 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2019 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

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

func NewZero(n int) Vector

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

func TensorProduct(v0 ...Vector) Vector

TensorProduct returns the vector resulting from multipling the all vectors passed as arguments together.

func TensorProductN

func TensorProductN(v0 Vector, bit ...int) Vector

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

func (v0 Vector) Add(v1 Vector) Vector

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) Apply

func (v0 Vector) Apply(mat matrix.Matrix) Vector

Apply returns the vector resulting from multiplying the vector by the matrix.

func (Vector) Clone

func (v0 Vector) Clone() Vector

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

func (v0 Vector) Dimension() int

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

func (v0 Vector) Dual() Vector

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

func (v0 Vector) Equals(v1 Vector, eps ...float64) bool

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

func (v0 Vector) IsOrthogonal(v1 Vector) bool

IsOrthogonal returns true if the two vectors are othogonal to each other: their inner product is zero.

func (Vector) IsUnit

func (v0 Vector) IsUnit() bool

IsUnit returns true if the normalized value of the vector elements is 1.

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

func (v0 Vector) OuterProduct(v1 Vector) matrix.Matrix

OuterProduct returns the matrix that results from applying the outer product between the two vectors.

func (Vector) TensorProduct

func (v0 Vector) TensorProduct(v1 Vector) Vector

TensorProduct returns the vector that results from applying the tensor product between the two vectors.

Jump to

Keyboard shortcuts

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