# Vectors and Matrices (Arrays)

In addition to scalars, Templex supports one- and two-dimensional arrays.

One-dimensional arrays can represent vectors (a row or a column), while two-dimensional arrays can represent matrices. Templex provides a number of functions and operators for performing vector and matrix mathematics, such as cross product, inversion, and concatenation.

Using vectors and matrices can simplify your templates. For instance, the coordinates for two points can be assigned to six variables:
{pt1_x = 1.0}
{pt1_y = 2.0}
{pt1_z = 3.0}

{pt2_x = 4.0}
{pt2_y = 5.0}
{pt2_z = 6.0}
and the midpoint can be calculated with the following formulae:
{pt3_x = (pt1_x + pt2_x) / 2}
{pt3_y = (pt1_y + pt2_y) / 2}
{pt3_z = (pt1_z + pt2_z) / 2}
These nine lines can be replaced with the following three by defining the points as vectors:
{pt1 = {1.0, 2.0, 3.0} }
{pt2 = {4.0, 5.0, 6.0} }

{pt3 = (pt1 + p2) / 2}
The following example illustrates the use of vector and matrix functions and operators:
{
pt = {1.0, 2.0}
theta = PI/4
c = cos(theta)
s = sin(theta)
rot = { {c , -s},  {s, c} }
pt1 = pt * rot
pt2 = pt1 * rot
pt3 = pt2 * inverse(rot)
if (pt1 == pt3) echo ("same")
}
The following is an example of using a string array:
{
filelist = {"file1", "file2", "file3"}
foreach (filename = filelist)
open(filename)
filename
close
endloop
}