Matrices

FISH supports multidimensional matrices composed of integers or floating-point values. Summation and multiplication of equally sized matrices are supported. A number of additional methods, detailed in the Matrix Utilities section, are available for matrix manipulation. These include matrix transpose, inversion, matrix determinant calculation and LU decomposition, among other operations. The math.outer.product performs the outer product of two vectors, returning a matrix. One should also be aware that a matrix can be converted to an array with the array.convert method. Matrices may be created from tensors.

The example below illustrates some simple matrix manipulations.

model new
; Matrix functionality tests
fish define setup
   alan = matrix(4,4)
   alan(1,3) = 6
   alan(2,1) = 2.2
   alan(3,4) = 6.6
   alan(4,2) = math.pi
end
@setup
[alan(4,2)]

fish define setup2
   alan = matrix.transpose(alan)
end
@setup2
[alan(2,4)]

fish define sum_tests
   herp = matrix(2,2)
   derp = matrix(2,2)
   serp = matrix(2,2)

   herp(1,1) = 6
   herp(1,2) = -1
   herp(2,1) = -3
   herp(2,2) = 2
   
   derp(1,1) = 4
   derp(1,2) = 3
   derp(2,1) = -7
   derp(2,2) = 0
   
   klerp = herp + derp
   werp = herp - derp
   serp = herp * derp
   
end
@sum_tests
[klerp(1,1)] 
[werp(1,1)] 
[serp(1,1)] 
   

fish define test
   local first = vector(2,4,3)
   local second = vector(8,1,5)
   local prod = math.outer.product(first, second)
   output = array.convert(prod);
end
@test
[output(1,1)]