# 2.5: Array Operations

• • R.L. Cerro, B. G. Higgins, S Whitaker
• Professors (Chemical Engineering) at University of Alabama at Huntsville & University of California at Davis

In general, one needs more than one quantity or number to define the properties of an object. For example, to define the density of a solution one needs both the mass and the volume, and to define the position of a point in three-dimensional space one needs a set of three numbers known as coordinates. When defining the chemical composition of mixtures, one must specify the concentration of each of the species present in the mixture. A gaseous mixture is not specified simply stating that it contains ten moles. One must specify, for example, that there are three moles of water, two moles of oxygen, and five moles of hydrogen.

To deal with the multi-dimensional aspects of the real world, one needs to organize sets of numbers (or symbols, names, functions, etc.) into ordered, recognizable structures and one needs to define ways to perform mathematical operations on these structures. In other words, one needs to define an algebra associated with the structures so that one can add, subtract, multiply, and divide the elements of the structure. To represent groups of numbers, we will often work with arrays which are ordered sets of numbers. Two-dimensional arrays are organized into rows and columns while higher dimension arrays are organized in pages similar to the pages of a spreadsheet. Unlike matrices, the numbers forming the elements of an array may be of a totally different kind. Some of the numbers may represent pressures, other temperatures, and some may represent concentrations. The only requirement for the definition of arrays is that all elements are organized in a pre-determined way.

There are many array operations that are crucial to the efficient use of computers. In this text, we identify arrays by the use of braces, $$\{ \}$$, and three examples of one-dimensional arrays are given by

$\begin{Bmatrix} {a_{1} } & {a_{2} } & {a_{3} } & {a_{4} } \end{Bmatrix} , \quad \begin{Bmatrix} {b_{1} } & {b_{2} } & {b_{3} } & {b_{4} } \end{Bmatrix}, \quad \begin{Bmatrix} {c_{1} } \\ {c_{2} } \\ {c_{3} } \\ {c_{4} } \end{Bmatrix} \label{20}$

In terms of the first two arrays, we define the operation of addition according to

$\begin{Bmatrix} {a_{1} } & {a_{2} } & {a_{3} } & {a_{4} } \end{Bmatrix} + \begin{Bmatrix} {b_{1} } & {b_{2} } & {b_{3} } & {b_{4} } \end{Bmatrix}=\begin{Bmatrix} {a_{1} +b_{1} } & { a_{2} +b_{2} } & { a_{3} +b_{3} } & {a_{4} +b_{4} } \end{Bmatrix} \label{21}$

However, we cannot add the following arrays

$\begin{Bmatrix} {a_{1} } & {a_{2} } & {a_{3} } & {a_{4} } \end{Bmatrix} + \begin{Bmatrix} {c_{1} } \\ {c_{2} } \\ {c_{3} } \\ {c_{4} } \end{Bmatrix}=\text{ Error!} \label{22}$

because array addition is only defined for conforming arrays. In order for arrays to conform, they must have the same number of rows and columns, thus the following addition of arrays is possible:

$\begin{Bmatrix} {a_{1} } \\ {a_{2} } \\ {a_{3} } \\ {a_{4} } \end{Bmatrix} + \begin{Bmatrix} {c_{1} } \\ {c_{2} } \\ {c_{3} } \\ {c_{4} } \end{Bmatrix}=\begin{Bmatrix} {a_{1} +c_{1} } \\ {a_{2} +c_{2} } \\ {a_{3} +c_{3} } \\ {a_{4} +c_{4} } \end{Bmatrix} \label{23}$

This type of operation is common in many types of analysis, and when the arrays, or lists, become very large the computational problem becomes very tedious. Any repetitive computation can be accomplished by software programs, and in the following paragraph we list several array operations that are especially useful.

Array multiplication by a scalar is defined according to

$s\begin{Bmatrix} {a_{1} } & {a_{2} } & {a_{3} } & {a_{4} } \end{Bmatrix}=\begin{Bmatrix} {sa_{1} } & {sa_{2} } & {sa_{3} } & {sa_{4} } \end{Bmatrix} \label{24}$

while array multiplication by an array takes the form

$\begin{Bmatrix} {a_{1} } & {a_{2} } & {a_{3} } & {a_{4} } \end{Bmatrix}\begin{Bmatrix} {b_{1} } & {b_{2} } & {b_{3} } & {b_{4} } \end{Bmatrix}=\begin{Bmatrix} {a_{1} b_{1} } & {a_{2} b_{2} } & {a_{3} b_{3} } & {a_{4} b_{4} } \end{Bmatrix} \label{25}$

Array division by a scalar is defined in the obvious manner, while array division by an array takes the form

$\begin{Bmatrix} {a_{1} } & {a_{2} } & {a_{3} } & {a_{4} } \end{Bmatrix}{ {\left/ { { \begin{Bmatrix} {b_{1} } & {b_{2} } & {b_{3} } & {b_{4} } \end{Bmatrix} }} \right. } \begin{Bmatrix} {b_{1} } & {b_{2} } & {b_{3} } & {b_{4} } \end{Bmatrix} } =\begin{Bmatrix} {a_{1} /b_{1} } & {a_{2} /b_{2} } & {a_{3} /b_{3} } & {a_{4} /b_{4} } \end{Bmatrix} \label{26}$

An array can be raised to a scalar power according to

$\begin{Bmatrix} {a_{1} } & {a_{2} } & {a_{3} } & {a_{4} } \end{Bmatrix}^{b} =\begin{Bmatrix} {a_{1}^{b} } & {a_{2}^{b} } & {a_{3}^{b} } & {a_{4}^{b} } \end{Bmatrix} \label{27}$

and an array can be raised to an array power that leads to the relation

$\begin{Bmatrix} {a_{1} } & {a_{2} } & {a_{3} } & {a_{4} } \end{Bmatrix}^{\begin{Bmatrix} {b_{1} } & {b_{2} } & {b_{3} } & {b_{4} } \end{Bmatrix}} =\begin{Bmatrix} {a_{1}^{b_{1} } } & {a_{2}^{b_{2} } } & {a_{3}^{b_{3} } } & {a_{4}^{b_{4} } } \end{Bmatrix} \label{28}$

One must remember that these are defined operations and they are defined because they are so common and so useful in engineering analysis. It is important that these array operations not be confused with matrix operations that are specified by the classic rules of matrix algebra.

In the previous paragraph, several algebraic operations were clearly defined for one-dimensional arrays. Under certain circumstances, we would like to represent these operations in compact notation and this requires the introduction of special nomenclature. We have already done this in Sec. $$2.2$$ where we made us of lower case, boldface font to identify the force and velocity vectors, i.e., $$\mathbf{f}$$ and $$\mathbf{v}$$. To express one-dimensional arrays in compact notation, we use the representation given by12

${\text{a}}=\begin{Bmatrix} {a_{1} } & {a_{2} } & {a_{3} } & {a_{4} } \end{Bmatrix} \label{29}$

and this allows us to express Equation \ref{28} in the following compact form

${\text{a}}^{\text{b}} ={\text{c}} \label{30}$

This type of nomenclature is only useful if one visualizes Equation \ref{28} when one sees Equation \ref{30}. This means that one must be able to interpret the array $$\text{c}$$ according to

${\text{c}}=\begin{Bmatrix} {a_{1}^{b_{1} } } & {a_{2}^{b_{2} } } & {a_{3}^{b_{3} } } & {a_{4}^{b_{4} } } \end{Bmatrix} \label{31}$

In using Equation \ref{30} as a compact version of Equation \ref{28}, we are confronting two classic problems associated with nomenclature. First, compact nomenclature is only useful if one can visualize the details and second, there are not enough letters and simple fonts to take care of all our needs.

Two-dimensional arrays are also useful in engineering calculations, and we identify them using uppercase letters according to

$\mathrm{A}=\begin{Bmatrix} {a_{11} } & {a_{12} } & {a_{13} } \\ {a_{21} } & {a_{22} } & {a_{23} } \\ {a_{31} } & {a_{32} } & {a_{33} } \end{Bmatrix} \label{32}$

If an array has the same number of rows and columns, it is called a square array. The following two square arrays have the special characteristic that the rows of array $$\mathrm{A}$$ are equal to the columns of array $$\mathrm{B}$$ and

$\mathrm{A}=\begin{Bmatrix} {3} & {4} & {-2} \\ {8} & {-2} & {-7} \\ {5} & {-3} & {4} \end{Bmatrix} , \quad \mathrm{B}=\begin{Bmatrix} {\rm 3} & {\rm 8} & {\rm 5} \\ {\rm 4} & {\rm -2} & {-3} \\ {\rm -2} & {-7} & {4} \end{Bmatrix} \label{33}$

that the columns of array $$\mathrm{A}$$ are equal to the rows of array $$\mathrm{B}$$. We call the array $$\mathrm{B}$$ the transpose of array $$\mathrm{A}$$ and we give it the special symbol $$\mathrm{A}^{\rm T}$$ so that Eqs. \ref{33} take the form

$\mathrm{A}=\begin{Bmatrix} {3} & {4} & {-2} \\ {8} & {-2} & {-7} \\ {5} & {-3} & {4} \end{Bmatrix} , \quad \mathrm{A}^{\rm T} =\begin{Bmatrix} {\rm 3} & {\rm 8} & {\rm 5} \\ {\rm 4} & {\rm -2} & {-3} \\ {\rm -2} & {-7} & {4} \end{Bmatrix} \label{34}$

Given that $$\mathrm{A}^{\rm T}$$ is the transpose of $$\mathrm{A}$$, one can see that $$\mathrm{A}$$ is also the transpose of $${\text{a}}^{\rm T}$$, and one is obtained from the other by interchanging rows and columns.

## 2.5.1 Units

The addition and subtraction of arrays, in particular $$1\times 4$$ arrays, can be used to determine the units of various derived quantities. This is accomplished by the use of the $$1\times 4$$ array of exponents in which the four entries are the exponents of the four fundamental standards given by

mass, length, time, electric charge

For example, in terms of the four fundamental units, we represent the units of force as

$\left( \begin{array}{c} \text{units of} \\ \text{force}\end{array} \right) = \frac{M L}{T^{2} } =M^{ 1} L^{ 1} T^{ -2} \label{35a}$

in which we have used $$M$$, $$L$$, and $$T$$ to represent the units of mass, length, and time. The $$1\times 4$$ array of exponents associated with force is given by

${\rm f}=\begin{Bmatrix} {1} & {-1} & {-2} & {0} \end{Bmatrix} \label{35b}$

The units of area are given by

$\left( \begin{array}{c} \text{units of} \\ \text{area}\end{array} \right) =L^{2} \label{36a}$

and the array of exponents in this case takes the form

${\text{a}}=\begin{Bmatrix} {0} & {2} & {0} & {0} \end{Bmatrix} \label{36b}$

Pressure is the force per unit area, and we can obtain the fundamental units of pressure by dividing the force by the area to obtain

$\left( \begin{array}{c} \text{units of} \\ \text{pressure}\end{array} \right) =\frac{\left(M L/T^{2} \right)}{\left(L^{2} \right)} =\frac{M}{LT^{2} } =M^{1} L^{ -1} T^{ -2} \label{37a}$

Since division by the units is equivalent to subtraction of the exponents, the $$1\times 4$$ array of exponents for pressure can be obtained by

${\rm p}={\rm f} - {\text{a}} =\begin{Bmatrix} {1} & {-3} & {-2} & {0} \end{Bmatrix} \label{37b}$

in which we have used $${\rm p}$$ to indicate the array of exponents for pressure.

Example $$\PageIndex{1}$$: Dimensions of the kinematic viscosity

The kinematic viscosity is defined as the ratio of the viscosity, $$\mu$$, to the density, $$\rho$$, and it is designated by the symbol $$\nu$$. To be explicit, we express the kinematic viscosity as

$\nu =\frac{\mu }{\rho } \tag{1}\label{a}$

The units of the kinematic viscosity can be obtained from the matrices of exponents for $$\mu$$ and $$\rho$$, and from Table $$2.2.3$$ we see that these are given by

${\rm mu}=\begin{Bmatrix} {1} & {-1} & {-1} & {0} \end{Bmatrix} , \quad {\rm rho}=\begin{Bmatrix} {1} & {-3} & {0} & {0} \end{Bmatrix} \tag{2}\label{b}$

The division indicated in Equation \ref{a} indicates that we need to subtract these matrices to determine that the units of the kinematic viscosity, i.e.,

${\rm nu}={\rm mu} - {\rm rho} \tag{3}\label{c}$

Carrying out the subtraction of the two $$1\times 4$$ matrices given by Eqs. \ref{b} leads to

${\rm nu}=\begin{Bmatrix} {1} & {-1} & {-1} & {0} \end{Bmatrix} - \begin{Bmatrix} {1} & {-3} & {0} & {0} \end{Bmatrix}=\begin{Bmatrix} {0} & {2} & {-1} & {0} \end{Bmatrix} \tag{4}\label{d}$

This indicates that the units of the kinematic viscosity are given by

$\left( \begin{array}{c} \text{units of kinematic} \\ \text{ viscosity}\end{array} \right)=\frac{L^{2} }{T} =L^{2} T^{ -1} \tag{5}\label{e}$

and one example is given in Table $$2.2.3$$ where we see that the kinematic viscosity can be expressed in terms of meters squared per second.

Example $$\PageIndex{2}$$: Composition of a gas mixture

We have a gas mixture consisting of 5 kg of methane, 10 kg of ethane, 5 kg of propane, and 3 kg of butane, and we wish to know the number of moles of each component in the mixture. The number of moles are determined by dividing the mass by the molecular mass of each individual component and these molecular masses are given by

\begin{aligned} M W_{\text {methane }} & =16.0433 \ g/mol, & M W_{\text {ethane }}=30.07 \ g/mol \\ M W_{\text {propane }} & =44.097 \ g/mol, & M W_{\text {butane }}=58.124 \ g/mol \end{aligned}

Here we have two lists or arrays and the result we wish can be obtained by an array division as indicated by Eq. ref{26}. Alternatively the results can be obtained by hand according to

$\left\{\begin{array}{l} \text { moles of } \\ \text { methane } \end{array}\right\}=\frac{\text { mass of methane }}{\text { molecular mass of methane }}=\frac{5 \ kg}{16.043 \ g/mol}=311.7 \ mol$

$\left\{\begin{array}{l} \text { moles of } \\ \text { ethane } \end{array}\right\}=\frac{\text { mass of ethane }}{\text { molecular mass of ethane }}=\frac{10 \ kg}{30.07 \ g/mol}=332.6 \ mol$

$\left\{\begin{array}{l} \text { moles of } \\ \text { propane } \end{array}\right\}=\frac{\text { mass of propane }}{\text { molecular mass of propane }}=\frac{5 \ kg}{44.097 \ g/mol}=113.4 \ mol$

$\left\{\begin{array}{c} \text { moles of } \\ \text { butane } \end{array}\right\}=\frac{\text { mass of butane }}{\text { molecular mass of butane }}=\frac{3 \ kg}{58.124 \ g/mol}=51.6 \ mol$

It should be clear that repetitive operations of this type area especially suited to computer assisted calculations.