# Visualizing Linear Algebra Decompositions#

In this notebook we just demonstrate the utility function xyzpy.visualize_matrix on various linear algebra decompositions taken from scipy. This function plots matrices with the values of numbers directly mapped to color. By default, complex phase gives the hue, with

• real positive = blue

• real negative = orange

• imaginary positive = purple

• imaginary negative = green

whereas the magnitude gives the saturation, such that $$|z| \sim 0$$ gives white.

:

import xyzpy as xyz
import numpy as np
import scipy.linalg as sla


First we’ll start with a non-symmetric random matrix with some small complex parts:

:

X = np.random.randn(20, 20) + 0.01j * np.random.rand(20, 20)
xyz.visualize_matrix(X, figsize=(2, 2))

: ## Singular Value Decomposition#

:

xyz.visualize_matrix(sla.svd(X), gridsize=(1, 3), figsize=(6, 6))

: The 1D array of real singular values in decreasing magnitude is shown as a diagonal.

## Eigen-decomposition#

:

xyz.visualize_matrix(sla.eig(X), figsize=(4, 4))

: Here we see the introduction of many complex numbers far from the real axis.

## Schur decomposition#

:

xyz.visualize_matrix(sla.schur(X), figsize=(4, 4))

: If you look closely here at the color sequence of the left diagonal it follows the eigen decomposition.

:

xyz.visualize_matrix(sla.schur(X.real), figsize=(4, 4))

: ## QR Decomposition#

:

xyz.visualize_matrix(sla.qr(X), figsize=(4, 4))

: ## Polar Decomposition#

:

xyz.visualize_matrix(sla.polar(X), figsize=(4, 4))

: ## LU Decomposition#

:

xyz.visualize_matrix(sla.lu(X), figsize=(6, 6), gridsize=(1, 3))

: Multiplying the left matrix in reorders the rows of the $$L$$ factor:

:

xyz.visualize_matrix(sla.lu(X, permute_l=True), figsize=(4, 4))

: 