*Mathematica*. For the latest information, see Matrices and Linear Algebra.

# Matrix Types

Matrices in *Mathematica* can be constructed from all the different types of objects that *Mathematica* holds. They can contain machine-precision real and complex floating-point numbers, arbitrary-precision real and complex floating-point numbers, integers, rational numbers, and general symbolic quantities. This tutorial considers the different types of matrices that *Mathematica* supports.

## Numbers in *Mathematica*

In order to understand the different types of matrices that *Mathematica* can work with, it will help to get an overview of the different types of numbers that are supported. This section only gives an overview of numbers in *Mathematica*; further information is found in "Numbers".

machine-sizeInteger | integers represented by machine hardware |

Integer | arbitrary‐length exact integer |

Rational | (fractions) in lowest terms |

machine-sizeReal | approximate real number represented by machine hardware |

Real | approximate real number, with any specified precision |

Complex | complex number of the form number+numberI |

AlgebraicNumber | root of an algebraic equation |

exact numerical expression | composition of numbers and mathematical functions |

infinities and exceptions | various special numbers |

Intrinsic types of numbers in *Mathematica*.

*Mathematica*provides an arithmetic system that unifies all these different types of numbers. For many purposes it is not necessary to know that there are two different types of integer because both types flow together. For example, the integer is represented by machine hardware. If this is raised to the tenth power, the result is represented by software.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

These examples demonstrate the general point that *Mathematica* arithmetic traps overflows and underflows so that it can switch from machine to software numbers. Despite this it tries to use machine hardware functionality whenever possible, so that *Mathematica* computations can be fast.

### Exact versus Approximate Numbers

*Mathematica*is that it makes a distinction between exact and approximate numbers. This is done to support the symbolic side of

*Mathematica*. This example compares the computation of the Sin function for an integer and a real argument.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

This demonstrates that mathematical functions, such as Sin, maintain the nature of their input. If they get an exact argument, the result will be exact. If they get an approximate argument the result is approximate. This feature of *Mathematica* is essential to maintain the system as a symbolic system, but it stands in contrast to the operation of a purely numerical environment. For example, in many languages such as C or Java the equivalent computation would coerce the integer to a double and the result would be an approximate number.

This distinction means that when you work with numbers you need to be more aware of their types than is the case in many other languages.

In[3]:= |

Out[4]= |

### Mixed Mode Arithmetic

*Mathematica*takes the lowest precision of the input. For example, the following mixed computations all return approximate results.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

## Matrices in *Mathematica*

Matrices in *Mathematica* can contain many different types of elements.

In[1]:= |

Out[1]//MatrixForm= | |

In[2]:= |

Out[2]//MatrixForm= | |

In[3]:= |

Out[3]//MatrixForm= | |

In[4]:= |

Out[4]//MatrixForm= | |

In[5]:= |

Out[5]//MatrixForm= | |

In[6]:= |

Out[6]//MatrixForm= | |

In[7]:= |

Out[7]//MatrixForm= | |

These different types of matrices can be put into categories according to the types of technique used for computing with them.

machine-precisionReal | standard numerical techniques |

machine-precisionComplex | |

arbitrary-precisionReal | arbitrary‐precision numerical techniques |

arbitrary-precisionComplex | |

Integer | symbolic algebra techniques |

Rational | |

exactComplex | |

symbolic |

Different types of matrices in *Mathematica*.

These three different categories are briefly reviewed.

#### Standard Numerical Techniques

In *Mathematica*, matrix computations involving machine-precision Real and machine-precision approximate Complex numbers are carried out with standard numerical techniques. In many cases computations involve optimized libraries, many of which are described in "Software References".

An important goal for many of these computations is to match and surpass the performance of any software package that is dedicated to machine-precision numbers. This is in keeping with the design goals of *Mathematica*, as described under "Design Principles of *Mathematica*". In the case of linear algebra computations, *Mathematica* makes use of a considerable amount of sophisticated technology, some of which is described under "Performance of Linear Algebra Computation".

#### Arbitrary-Precision Numerical Techniques

In *Mathematica*, matrix computations involving arbitrary-precision Real and arbitrary-precision approximate Complex numbers are carried out with special numerical libraries. These libraries are adapted from standard libraries so they can work for arbitrary-precision computations.

More information can be found in the section "Arbitrary-Precision Matrices".

#### Symbolic Algebra Techniques

Matrix computations involving exact numbers and general symbolic techniques are carried out with computer algebra techniques.

All computations provided for numerical matrices are also available for symbolic matrices. This meets the design goal of integrating symbolic and numerical computation.

### Mixed Mode Matrices

This section describes what happens if the input matrix contains a mixture of different types of entries.

In[1]:= |

Out[2]= |

In[3]:= |

Out[4]= |

In[5]:= |

Out[6]= |

In[7]:= |

Out[7]= |

In[8]:= |

Out[9]= |

In[10]:= |

Out[10]= |

In[11]:= |

Out[12]= |

In some other computation systems an input matrix of integers would be converted to a floating-point matrix. *Mathematica* does not do this, so that it can support symbolic computation. However, it means that users need to be aware of the differences. This is because the time required for a symbolic technique can be quite different from a machine-precision technique; in many cases the symbolic computation will take much longer.

## Complex Matrices

Complex matrices in *Mathematica* are defined in a way that is completely consistent with other types of matrices such as those that involve real numbers. All the functions that work for real matrices work for complex matrices.

In[1]:= |

Out[3]//MatrixForm= | |

In[4]:= |

Out[6]//MatrixForm= | |

## Arbitrary-Precision Matrices

*Mathematica*arbitrary-precision computations support a form of arithmetic known as significance arithmetic. The fundamental idea of significance arithmetic is that a number is seen as an approximation with an error specified by its precision. When a number is used in a computation the precision of the result may be different according to the properties of the function. For example, here is a number with 30 digits of precision.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

*Mathematica*, linear algebra computations generally do not use significance arithmetic. They are carried out in what is known as fixed precision, where computations are done with fixed numbers of digits with no attempt to track the error in individual operations. Error tracking is done on an algorithmic level, issuing warnings, for example, when the solution of a linear system may not be correct.

In[4]:= |

Out[5]= |

In[6]:= |

Out[6]= |