使用Cayley-Hamilton定理在MATLAB中求解方陣的逆矩陣


讓我們從簡要討論“什麼是方陣的逆矩陣”和“Cayley-Hamilton定理的重要性”開始本教程。

什麼是方陣的逆矩陣?

線上性代數中,有一個基本概念叫做方陣的逆矩陣。考慮一個方陣‘A’,那麼將存在另一個方陣‘A-1’,使得A.A-1 = I,其中I是單位矩陣。這裡,A-1被稱為方陣A的逆矩陣。

需要注意的是,對於給定的方陣,只有當它的行列式不為零時才能找到逆矩陣。可以計算逆矩陣的矩陣也稱為非奇異矩陣,而無法直接計算逆矩陣的矩陣稱為奇異矩陣。

矩陣逆矩陣的計算在求解線性方程組中起著至關重要的作用。它在工程、計算機圖形學、模擬等各個領域都有應用。

Cayley-Hamilton定理

Cayley-Hamilton定理是線性代數中的一個基本定理,用於尋找方陣與其特徵方程之間的關係。

根據Cayley-Hamilton定理,任何方陣A都滿足其自身的特徵方程,當它在矩陣本身進行計算時。

數學上,如果A是一個方陣,p(x)是其特徵方程,則

p(A) = 0

其中,0是與矩陣A同階的零矩陣。

矩陣A的特徵方程由下式給出:

$$\mathrm{p(x)=|A−xI|}$$

這裡,“x”是一個標量變數,“I”是方陣“A”的單位矩陣。

使用Cayley-Hamilton定理求解方陣逆矩陣的步驟

這裡解釋了使用Cayley-Hamilton定理求解方陣逆矩陣的分步過程

步驟 (1) – 首先,計算給定方陣A的特徵方程,即

$$\mathrm{p(x)=|A−xI|}$$

其中,“I”是方陣A的單位矩陣。

步驟 (2) – 透過用方陣A替換特徵方程p(x)中的變數“x”,得到矩陣方程p(A)。

步驟 (3) – 透過求解矩陣方程p(A)得到零矩陣,即

p(A)=0

其中,0是與方陣A大小相同的零矩陣。

步驟 (4) – 寫出矩陣方程,即

$$\mathrm{A.A^{-1}=I}$$

其中,A-1是方陣A的逆矩陣。

步驟 (5) – 透過執行矩陣運算求解矩陣方程,以得到逆方陣A-1

這就是使用Cayley-Hamilton定理求解方陣逆矩陣所涉及的所有步驟。

在概述了方陣的逆矩陣和Cayley-Hamilton定理之後,現在讓我們討論如何在MATLAB中使用Cayley-Hamilton定理求解方陣的逆矩陣。

在MATLAB中使用Cayley-Hamilton定理求解方陣的逆矩陣

以下MATLAB中的示例程式演示瞭如何在MATAB中使用Cayley-Hamilton定理求解方陣的逆矩陣。

示例

% MATLAB code to find Inverse of Sq. Matrix using Cayley Hamilton Theorem
% Create a sample square matrix
A = [1, 4, 2; 4, -5, 6; 3, 2, -9];

% Calculate coefficients of characteristic equation of matrix A
c = poly(A);

% Calculate number of coefficients in characteristic equation of matrix A
n = length(c);

% Initialize the inverse matrix
inv = c(1) * A^(n-2);

% Apply Cayley Hamilton theorem to calculate the inverse matrix A
for i = 2:n-1
    inv = inv + c(i) * A^(n-i-1);
end

% Verify that |A| = 0 or not
if round(c(n)) == 0
    disp('The square matrix A is a singular matrix and its inverse does not exist.')
else
    inv = inv / (-c(n));
    disp('The inverse of square matrix A:')
    disp(inv)
end

輸出

The inverse of square matrix A:
   1.1186e-01   1.3559e-01   1.1525e-01
   1.8305e-01  -5.0847e-02   6.7797e-03
   7.7966e-02   3.3898e-02  -7.1186e-02

示例

現在,讓我們考慮另一個示例,在這個示例中,我們將嘗試求解奇異方陣的逆矩陣,並檢視結果。

% MATLAB code to find Inverse of Sq. Matrix using Cayley Hamilton Theorem
% Create a sample square matrix
A = [1, 2, 3; 2, 4, 6; 3, 6, 9];

% Calculate coefficients of characteristic equation of matrix A
c = poly(A);

% Calculate number of coefficients in characteristic equation of matrix A
n = length(c);

% Initialize the inverse matrix
inv = c(1) * A^(n-2);

% Apply Cayley Hamilton theorem to calculate the inverse matrix A
for i = 2:n-1
    inv = inv + c(i) * A^(n-i-1);
end

% Verify that |A| = 0 or not
if round(c(n)) == 0
    disp('The square matrix A is a singular matrix and its inverse does not exist.')
else
    inv = inv / (-c(n));
    disp('The inverse of square matrix A:')
    disp(inv)
end

輸出

The square matrix A is a singular matrix and its inverse does not exist.

結論

在本教程中,我們討論瞭如何在MATLAB中使用Cayley-Hamilton定理求解方陣的逆矩陣。為了更好地理解,我們用適當的示例解釋了理論概念。

更新於: 2023年9月7日

279 次瀏覽

開啟你的職業生涯

透過完成課程獲得認證

開始學習
廣告