# Matrices Author:

Categories: Tutorials

Tagged with:

## USING MATRICES IN GRASSHOPPER

This tutorial is discribing the way, how we use matrices in Grasshopper.

### MATRIX

Matrix is described as a rectangular array of numeric or algebraic quantities subject to mathematical operations. Generally it contains m rows and n columns. ### MATRIX NOTATION

To write a matrix in Grasshopper we have to use the component Construct Matrix. It has 3 input parametres: R (Number of rows in the matrix), C (Number of columns in the matrix) and V (Optional matrix values). And finally we use the component Display matrix. ### SCALAR MULTIPLICATION

First we have to construct the matrix. This is described in the part 1. Then we have to use the component Deconstruct Matrix, that deconstructs the matrix into its component parts. It gives us 3 output parametres: R (Number of rows in the matrix), C (Number of columns in the matrix) and V (Optional matrix values). Then we milltiplicate V by real number. And now we have to construct the matrix again by using the component Construct Matrix. So Grasshopper can’t operate with matrices so easily, we have to construct matrix, then deconstruct a and finally again construct. ### MULTIPLYING MATRICES

The multiplication one matrix by another is little complicated. We have to construct 2 matrices, shown in part 1. Then use the component Deconstruct Matrix. The component Path Mapper is being connected, that performs lexical operations on data trees. Then we multiplicate matrices as is displayed in the following scheme. C11 = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41. Then we use the component Multiplication and Mass Addition, that performs mass additon of a list of items. The R (Result) is connected to V (Values), that has to be flatten, of the component Construct Matrix. ### MULTIPLICATION MATRICES IN VB

Another way to multiplicate matrices by using component VB is maybe a little easier.

Dim m As New Matrix(2, 2)

m(0, 0) = 2.0

m(0, 1) = 3.0

m(1, 0) = 5.0

m(1, 1) = 7.0

Dim b As New Matrix(2, 2)

b(0, 0) = 11.0

b(0, 1) = 13.0

b(1, 0) = 17.0

b(1, 1) = 19.0

Dim c As Matrix = m * b

A = String.Format(“2×2 Matrix:” + Environment.NewLine + “{0} {1}” + Environment.NewLine + “{2} {3}”, _

c(0, 0), c(0, 1), _

c(1, 0), c(1, 1)) ### SIERPINSKI TRIANGLE MADE BY USING MATRICES 