# Orthogonalization of vectors

## Introduction

In this article, we will study the Gram-Schmidt approach to orthogonalization of vectors. In the process, we will build an intuition to operations from a geometric perspective with an interactive demonstration.

## Prerequisites

To understand orthogonalization of vectors, we recommend familiarity with the concepts in

Follow the above links to first get acquainted with the corresponding concepts.

## Orthogonality

We saw in the earlier demo that the dot product of two vectors is zero if the angle between them is 90 degrees, since $\cos 90^\circ = 0$. Such non-zero vectors with a zero dot product are said to be mutually orthogonal.

Also, if two orthogonal vectors are also unit vectors, then they are said to be orthonormal.

If a set of vectors is the basis for a space and they are also mutually orthonormal, then they are known as the orthonormal basis of that space. Note that the X-axis and the Y-axis are the orthonormal basis of a Cartesian coordinate system and any point on that space can be defined in terms of their X and Y coordinates.

An understanding of orthogonal or orthonormal vectors is important for ML applications.

## Orthogonalization

Data or models seldom automatically lead to orthogonal vectors. But many applications, such as machine learning, benefit from the representation of the dataset along orthonormal basis. For such applications of linear algebra, it is a common practice to discover the orthonormal basis for any given set of vectors.

Orthogonalization is the process used to arrive at orthogonal vectors from any given set of vectors. The popular algorithm used for this approach is known as the Gram-Schmidt approach.

## Gram-Schmidt Algorithm

Here's how the Gram-Schmidt approach for orthgonalization works for a set of vectors $\{\va_1, \ldots, \va_n \}$ into a set of mutually orthogonal vectors $\{\vx_1, \ldots, \vx_n \}$

1. Let $\vx_1 = \va_1$.
2. Compute the projection of the next vector $\va_2$ onto $\vx_2$. Intuitively, this is a portion of $\va_2$ in the direction of $\vx_1$. $$\text{proj}_{\vx_1}(\va_2) = \frac{\va_2 \cdot \vx_1}{\vx_1 \cdot \vx_1} \vx_1.$$
3. Now we need to just figure out the portion of $\va_2$ that cannot be explained by the projection $\va_2(\vx_1)$. Remaining means subtraction, and that's what we will do. $$\vx_2 = \va_2 - \text{proj}_{\vx_1}(\va_2)$$
4. Continue the process for the next vector $\va_i$, but this time identify the portion that is left after removing components for all previous orthogonal vectors. $$\vx_i = \va_i - \sum_{j = 1}^{i-1} \text{proj}_{\vx_j}(\va_i)$$

## Orthogonalization: demo

Interact with the orthogonalization demo next to get a good intuitive feel for the process. Check out what happens when you change either of the input vectors. Note the change in the projection and the resulting orthogonalization result.

In this demo, $\text{proj}_{\va}(\vb)$ is the projection of $\vb$ on $\va$. It is calculated as

$$\text{proj}_{\va}(\vb) = \frac{ \va \cdot \vb}{ \vb \cdot \vb} \va$$

Also, $\text{orth}_{\va}(\vb)$ is the component of $\vb$ that is orthogonal to $\va$. It is calculated as

$$\text{orth}_{\va}(\vb) = \vb - \text{proj}_{\va}(\vb)$$

Thus, intuitively, it can be seen that $\vb$ can be split into two components — one that is along the same direction as $\va$ and the remaining which is orthogonal to that direction. This important property is used in several linear algebra techniques.

## Where to next?

Now that you are an expert in vectors, it is time to build expertise in other topics in linear algebra.