CIRCULANT
Constructs a circulant matrix where each row is a cyclic shift of the previous row. The first row is the cyclic shift of the column provided.
Excel Usage
=CIRCULANT(column)
column(list[list], required): First column of the matrix.
Returns (list[list]): 2D array representing the circulant matrix.
Example 1: Circulant matrix from 3 elements
Inputs:
| column | ||
|---|---|---|
| 1 | 2 | 3 |
Excel formula:
=CIRCULANT({1,2,3})
Expected output:
| Result | ||
|---|---|---|
| 1 | 3 | 2 |
| 2 | 1 | 3 |
| 3 | 2 | 1 |
Example 2: Circulant matrix from column-style input
Inputs:
| column |
|---|
| 1 |
| 2 |
| 3 |
Excel formula:
=CIRCULANT({1;2;3})
Expected output:
| Result | ||
|---|---|---|
| 1 | 3 | 2 |
| 2 | 1 | 3 |
| 3 | 2 | 1 |
Example 3: Circulant matrix from decimal values
Inputs:
| column | ||
|---|---|---|
| 1.5 | 2.5 | 3.5 |
Excel formula:
=CIRCULANT({1.5,2.5,3.5})
Expected output:
| Result | ||
|---|---|---|
| 1.5 | 3.5 | 2.5 |
| 2.5 | 1.5 | 3.5 |
| 3.5 | 2.5 | 1.5 |
Example 4: Circulant matrix from scalar input
Inputs:
| column |
|---|
| 7 |
Excel formula:
=CIRCULANT(7)
Expected output:
7
Python Code
import numpy as np
from scipy.linalg import circulant as scipy_circulant
def circulant(column):
"""
Construct a circulant matrix.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.circulant.html
This example function is provided as-is without any representation of accuracy.
Args:
column (list[list]): First column of the matrix.
Returns:
list[list]: 2D array representing the circulant matrix.
"""
try:
def to2d(x):
return [[x]] if not isinstance(x, list) else x
column = to2d(column)
if not isinstance(column, list) or not all(isinstance(row, list) for row in column):
return "Error: column must be a 2D list"
flat_column = []
for row in column:
for value in row:
try:
flat_column.append(float(value))
except (TypeError, ValueError):
return "Error: column must contain only numeric values"
if not flat_column:
return "Error: column must contain at least one numeric value"
c = np.array(flat_column, dtype=float)
res = scipy_circulant(c)
return res.tolist()
except Exception as e:
return f"Error: {str(e)}"Online Calculator
First column of the matrix.