go for 2x2 complex matrices

GoDoc GoLint


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!


First of all import m2c.

import "m2c"

Get the identity matrix

var id = m2c.I()

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)

Multiply two matrices.

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

var invA, err = m2c.Inv(a)