# How to Write Functionno to Calculate Eigenvalues in Julia

Julia is a powerful programming language designed for scientific computing, machine learning, data analysis, large-scale linear algebra, and distributed computing. It uses a combination of Python, C and Lisp, and supports multithreading.

It is also fast, both at runtime and during development. Its math qualities make it attractive to data scientists who need high-performance computing results.

## Functions

An eigenvalue is the particular set of scalar values associated with a linear transformation. A matrix is said to be a linear transformation if its eigenvectors satisfy the characteristic equation: (A – lI)k v = 0 for all generalized eigenvalues lI of A. The corresponding vectors v are known as eigenvectors of A, and a pair of eigenvectors is called an eigenpair.

Eigenvalues are most easily computed for square symmetric positive-definite matrices, but the principles underlying them extend to other situations. For example, the eigenvalues of a circle matrix are real numbers and can be found using the determinant of the circular covariance matrix.

To calculate eigenvalues for a matrix A, you use the function eig(A). The parameter balanceOption is an optional argument that disables a preliminary balancing step in the algorithm. The default value of balanceOption is ‘nobalance’.

Suppose you want to find the eigenvalues and eigenvectors of a 3-by-3 matrix A. First, create the matrix by using the function gallery(). Then, eig(A) computes the eigenvalues and eigenvectors for A. eig(A) returns the diagonal matrix D of eigenvalues and a full matrix W whose columns are the corresponding right eigenvectors, so that A*V = W*D. The eigenvectors in W are normalized such that the 2-norm of each is 1. You can verify this by multiplying any of the eigenvectors by A and seeing that the result is equal to A.

## Variables

The first step to finding eigenvalues is to enter your matrix values into the provided grid. Each value must be in the same row and column of the matrix. Once the grid is filled out, click on “Calculate” to calculate your eigenvalues and eigenvectors. For each eigenvalue, there are infinitely many corresponding eigenvectors that form an orthogonal subspace of your matrix. You can see this property at work in the Exploration Problem init:3x3tri. This vignette illustrates the same property using a variance-covariance matrix.

## Symbols

Symbols are the letters, numbers, or characters that represent a number or a variable. They can be used to express ideas in mathematical formulas, scientific notation, and computer code. They can also be used to convey information to other people who share the same language or culture. Using symbols can be especially helpful when working with complicated equations and data sets.

Matrix operations such as eigenvalue calculations are more easily performed with symbolic variables than numeric ones. MATLAB uses the eig function to find exact eigenvalues and eigenvectors for symbolic matrix objects. It is possible to create a numeric matrix from such a symbolic matrix, but this can slow computation time and introduce rounding error. Using numeric values instead of symbolic values is recommended whenever possible.

If you know the dimensions of a square symbolic matrix, you can use the eig function to calculate its eigenvalues and eigenvectors. It returns a vector of indices that relate the eigenvalues to their linearly independent eigenvectors. This vector can then be used to compute the eigenvalues and eigenvectors of another symbolic matrix.

[V,D] = eig(A) returns a diagonal matrix D of eigenvalues and a full matrix V whose columns are the corresponding right eigenvectors. It also returns a vector of indices p that correlates the eigenvalues to their linearly-dependent eigenvectors.

## Operators

Using the same operators as in a matrix multiplication, you can calculate eigenvalues and eigenvectors. Typically, eigenvectors will be column vectors and eigenvalues will be row vectors, though in some cases you may have to specify the format for these vectors.

For example, you can calculate a set of eigenvectors for a 3-by-3 matrix by multiplying the matrices with each other and reordering the columns. The resulting vectors should match up in order and value, as shown below.

Eigenvalues are real numbers that describe the amount of energy a wave function has, or more specifically the number of times the function multiplies itself. The word “eigen” is German for self, and this describes the fact that when an operator operates on a function, it will produce a constant, or a number, times the function.

When calculating eigenvalues, you will need to pass in an input matrix A and an output matrix B. The input matrix, A, must be a positive definite matrix and the output matrix, B, must be invertible. You can also specify a balance option, ‘nobalance’, which disables the preliminary balancing of the matrix. This method is more efficient, but it will not work for certain types of eigenvalues, such as the continuum eigenstates. These eigenvalues do not vanish as x –> +-x and therefore cannot be described by the normalized variance-covariance matrix (NVC). Consequently, a matrix like NVC will need to be transformed.