m2c

package module
v0.0.0-...-17b0533 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 2 Imported by: 1

README

m2c

go for 2x2 complex matrices

GoReference

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.

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 when the argument of the inversion operator is a matrix with determinant equal to zero.

func (*CannotInvertMatrixError) Error

func (e *CannotInvertMatrixError) Error() string

type Matrix

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

A 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 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 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 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.

Jump to

Keyboard shortcuts

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