vector

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: 3 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 is a vector of complex128.

func New

func New(z ...complex128) Vector

New returns a new vector of complex128.

Example
package main

import (
	"fmt"

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

func main() {
	v := vector.New(1, 0)
	fmt.Println(v)

}
Output:

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

func TensorProduct

func TensorProduct(v ...Vector) Vector
Example
package main

import (
	"fmt"

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

func main() {
	v := vector.New(1, 0)
	vv := vector.TensorProduct(v, v)
	fmt.Println(vv)

}
Output:

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

func TensorProductN

func TensorProductN(v Vector, n ...int) Vector
Example
package main

import (
	"fmt"

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

func main() {
	v := vector.New(1, 0)
	vv := vector.TensorProductN(v, 2)
	fmt.Println(vv)

}
Output:

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

func Zero

func Zero(n int) Vector

Zero returns a vector of length n with all elements zero.

Example
package main

import (
	"fmt"

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

func main() {
	v := vector.Zero(3)
	fmt.Println(v)

}
Output:

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

func (Vector) Add

func (v Vector) Add(w Vector) Vector

Add returns a vector of v+w.

func (Vector) Apply

func (v Vector) Apply(m matrix.Matrix) Vector

Apply returns a matrix product of v and m.

Example
package main

import (
	"fmt"

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

func main() {
	v := vector.New(1, 2)
	fmt.Println(v)

	m := matrix.New(
		[]complex128{1, 2},
		[]complex128{1, 3},
	)

	vv := v.Apply(m)
	fmt.Println(vv)

}
Output:

[(1+0i) (2+0i)]
[(5+0i) (7+0i)]

func (Vector) Clone

func (v Vector) Clone() Vector

Clone returns a clone of vector.

func (Vector) Complex

func (v Vector) Complex() []complex128

Complex returns a slice of complex128.

Example
package main

import (
	"fmt"

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

func main() {
	v := vector.New(1+2i, 3+4i)
	fmt.Println(v.Complex())

}
Output:

[(1+2i) (3+4i)]

func (Vector) Dimension

func (v Vector) Dimension() int

Dimension returns a dimension of vector.

Example
package main

import (
	"fmt"

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

func main() {
	v := vector.New(1+2i, 3+4i)
	fmt.Println(v.Dimension())

}
Output:

2

func (Vector) Dual

func (v Vector) Dual() Vector

Dual returns a dual vector.

func (Vector) Equals

func (v Vector) Equals(w Vector, eps ...float64) bool

Equals returns true if v and w are equal. If eps is not given, epsilon.E13 is used.

func (Vector) Imag

func (v Vector) Imag() []float64

Imag returns a slice of imaginary part.

Example
package main

import (
	"fmt"

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

func main() {
	v := vector.New(1+2i, 3+4i)
	for _, r := range v.Imag() {
		fmt.Println(r)
	}

}
Output:

2
4

func (Vector) InnerProduct

func (v Vector) InnerProduct(w Vector) complex128

InnerProduct returns the inner product of v and w.

Example
package main

import (
	"fmt"

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

func main() {
	v := vector.New(1, 0)
	vv := v.InnerProduct(v)
	fmt.Println(vv)

}
Output:

(1+0i)

func (Vector) IsOrthogonal

func (v Vector) IsOrthogonal(w Vector) bool

IsOrthogonal returns true if v and w are orthogonal.

Example
package main

import (
	"fmt"

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

func main() {
	v0 := vector.New(1, 0)
	v1 := vector.New(0, 1)
	o := v0.IsOrthogonal(v1)
	fmt.Println(o)

}
Output:

true

func (Vector) IsUnit

func (v Vector) IsUnit() bool

IsUnit returns true if v is unit vector.

func (Vector) Mul

func (v Vector) Mul(z complex128) Vector

Mul returns a vector of z*v.

func (Vector) Norm

func (v Vector) Norm() complex128

Norm returns a norm of vector.

Example
package main

import (
	"fmt"

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

func main() {
	v := vector.New(1, 2)
	n := v.Norm()
	fmt.Printf("%.4f", n)

}
Output:

(2.2361+0.0000i)

func (Vector) OuterProduct

func (v Vector) OuterProduct(w Vector) matrix.Matrix

OuterProduct returns the outer product of v and w.

Example
package main

import (
	"fmt"

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

func main() {
	v := vector.New(1, 0)
	vv := v.OuterProduct(v)
	fmt.Println(vv)

}
Output:

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

func (Vector) Real

func (v Vector) Real() []float64

Real returns a slice of real part.

Example
package main

import (
	"fmt"

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

func main() {
	v := vector.New(1+2i, 3+4i)
	for _, r := range v.Real() {
		fmt.Println(r)
	}

}
Output:

1
3

func (Vector) TensorProduct

func (v Vector) TensorProduct(w Vector) Vector

TensorProduct returns the tensor product of v and w.

Example
package main

import (
	"fmt"

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

func main() {
	v := vector.New(1, 0)
	vv := v.TensorProduct(v)
	fmt.Println(vv)

}
Output:

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

Jump to

Keyboard shortcuts

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