如何在Excel中生成旋转90度的酉矩阵?能否通过单元格公式实现?
Absolutely, you can create the exact rotated unitary matrix you’re looking for directly using Excel’s built-in functions—no pre-written matrices required. Let’s walk through how to do this, tailored to your 3阶 example and scalable to any size.
The Core Approach
You already know MUNIT(size) generates a standard unitary (identity) matrix. The target matrix you want is essentially the identity matrix with its rows reversed (which matches your 3阶 example: [0,0,1]; [0,1,0]; [1,0,0]). We can use Excel’s INDEX and SEQUENCE functions to dynamically reverse the row order of the MUNIT output.
The Array Formula
For an n-sized matrix, use this formula:
=INDEX(MUNIT(n), SEQUENCE(n, 1, n, -1), SEQUENCE(n))
Breakdown of the Formula:
MUNIT(n): Generates the standard n×n identity matrix.SEQUENCE(n, 1, n, -1): Creates a descending sequence from n to 1 (e.g., for n=3, this outputs3,2,1). This tellsINDEXto pull rows from the identity matrix in reverse order.SEQUENCE(n): Creates an ascending sequence from 1 to n, which selects all columns in each reversed row.
Example for 3阶 Matrix
If you input =INDEX(MUNIT(3), SEQUENCE(3,1,3,-1), SEQUENCE(3)) into a 3×3 cell range (as an array formula), you’ll get exactly the matrix you specified:
0 0 1 0 1 0 1 0 0
Notes for Usage:
- Excel Versions: This works natively in Excel 365/2021 with dynamic arrays (just press Enter). For older versions, you’ll need to enter it as an array formula using
Ctrl+Shift+Enter. - Scalability: Change the
nvalue to generate any size of the rotated matrix—no manual edits needed.
内容的提问来源于stack exchange,提问作者zexot

