m2c

package module
v0.0.0-...-0006966 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2017 License: MIT Imports: 2 Imported by: 1

README

m2c

go for 2x2 complex matrices

GoDoc GoLint

Description

Complex matrices 2x2 (a.k.a. m2c) are a wonderful land to explore. They are matrices of the form

     | a  b |
     | c  d |

Where a, b, c, d are complex numbers. I found Golang as the perfect language to implement them since it has complex128 data type, yeah!

Examples

First of all import m2c.

import "m2c"

Get the identity matrix

var id = m2c.I()
fmt.Printf("%v", id)
// {(1+0i) (0+0i) (0+0i) (1+0i)}

Multiply two matrices.

var a = m2c.Matrix{1, 0, 0, 1}
var b = m2c.Matrix{1, 1+i, 0, 1-i}

var c = m2c.Mul(a, b)

Invert a matrix.

var a = m2c.Matrix{2i, 0, 0, 1}

var invA, err = m2c.Inv(a)

if err != nil {
	log.Fatal(err)
}

License

MIT

Documentation

Overview

Package m2c implements complex matrices 2x2. Point your browser to http://g14n.info/m2c for more info.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Det

func Det(m Matrix) complex128

Det computes matrix determinant.

func Eq

func Eq(l Matrix, r Matrix) bool

Eq checks if two matrices are equal.

Types

type CannotInvertMatrixError

type CannotInvertMatrixError struct {
	// contains filtered or unexported fields
}

CannotInvertMatrixError complains cause it is not possible to invert a matrix if determinant is zero.

func (*CannotInvertMatrixError) Error

func (e *CannotInvertMatrixError) Error() string

type Matrix

type Matrix struct {
	A, B, C, D complex128
}

Matrix with two rows, two columns and Complex numbers as values.

func Add

func Add(l Matrix, r Matrix) Matrix

Add two matrices.

func Conj

func Conj(m Matrix) Matrix

Conj returns the conjugated matrix.

func I

func I() Matrix

I returns the identity matrix.

func Inv

func Inv(m Matrix) (Matrix, error)

Inv inverts given matrix respect to multiplication. If it has determinant equal to zero, an error will be returned as second argument.

func J

func J() Matrix

J returns the symplectic matrix.

func Mul

func Mul(l Matrix, r Matrix) Matrix

Mul multiplies two matrices. This operator is not commutative.

func Neg

func Neg(m Matrix) Matrix

Neg computes matrix inverse respect to addition.

func NewMatrix

func NewMatrix(a, b, c, d complex128) Matrix

Matrix contructor.

func Scalar

func Scalar(m Matrix, c complex128) Matrix

Scalar multiplies matrix by a complex number.

func Sub

func Sub(l Matrix, r Matrix) Matrix

Sub subtracts two matrices.

func T

func T(m Matrix) Matrix

T returns the transposed matrix.

func Zero

func Zero() Matrix

Zero returns the matrix with all zeros.

Jump to

Keyboard shortcuts

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