天天看點

OpenCascade Eigenvalues and Eigenvectors of Square Matrix

<a href="mailto:[email protected]">[email protected]</a>

Abstract. OpenCascade use the Jacobi method to find the eigenvalues and the eigenvectors of a real symmetric square matrix. Use class math_Jacobi to computes all eigenvalues and eigenvectors by using Jacobi method. The exception NotSquare is raised if the matrix is not square. No verification that the matrix is really symmetric is done.

Key words. Eigenvalues, Eigenvectors, OpenCascade, Matrix, Jacobi method,

1. Introduction

工程技術中的一些問題,如振動問題和穩定性問題,常可歸結為求一個方陣的特征值和特征向量的問題。數學中諸如方陣的對角化及解常微分方程等問題,也都有要用到特征值的理論。

定義:設A是n階矩陣,如果數λ和n維非零列向量x使關系式 Ax = λx成立,那麼這樣的數λ稱為方陣A的特征值,非零向量x稱為A對應于特征值λ的特征向量。

推論:若n階矩陣A與對角陣

OpenCascade Eigenvalues and Eigenvectors of Square Matrix

相似,則λ1,λ2,...,λn即是A的n個特征值。

定理:n階矩陣A與對角陣相似(即A能對角化)的充分必要條件是A有n個線性無關的特征向量。

推論:如果n階矩陣A的n個特征值互不相等,則A與對角陣相似。

當A的特征方程有重根時,就不一定有n個線性無關的的特征向量,進而不一定能對角化。一個n階矩陣具備什麼條件才能對角化呢?這是一個較複雜的問題。

定理:設A為n階對稱陣,則有正交陣P,使

OpenCascade Eigenvalues and Eigenvectors of Square Matrix

其中∧是以A的n個特征值為對角元的對角陣。

OpenCascacde中使用了Jacobi方法來計算對稱方陣的特征值和特征向量。本文對math_Jacobi的使用進行詳細說明。

2. Code Example

結合同濟第四版《線性代數》中的例子,來驗證Jacobi方法計算的結果。示例程式如下所示:

/*

*    Copyright (c) 2014 eryar All Rights Reserved.

*

*        File    : Main.cpp

*        Author  : [email protected]

*        Date    : 2014-06-22 21:46

*        Version : 1.0v

*    Description : Demonstrate how to find the eigenvalues and

*                  eigenvectors for a symmetric square Matrix.

*                  題目來自《線性代數》同濟 第四版

*                  

*/

#define WNT

#include &lt;math_Jacobi.hxx&gt;

#pragma comment(lib, "TKernel.lib")

#pragma comment(lib, "TKMath.lib")

/**

* OpenCascade use Jacobi method to find the eigenvalues and 

* the eigenvectors of a real symmetric square matrix.

void EvalEigenvalue(const math_Matrix &amp;A)

{

    math_Jacobi J(A);

    std::cout &lt;&lt; A &lt;&lt; std::endl;

    if (J.IsDone())

    {

        std::cout &lt;&lt; "Jacobi: \n" &lt;&lt; J &lt;&lt; std::endl;

        //std::cout &lt;&lt; "Eigenvalues: \n" &lt;&lt; J.Values() &lt;&lt; std::endl;

        //std::cout &lt;&lt; "Eigenvectors: \n" &lt;&lt; J.Vectors() &lt;&lt; std::endl;

        for (Standard_Integer i = A.LowerRow(); i &lt;= A.UpperRow(); ++i)

        {

            math_Vector V(1, A.RowNumber());

            J.Vector(i, V);

            std::cout &lt;&lt; "Eigenvalue: " &lt;&lt; J.Value(i) &lt;&lt; std::endl;

            std::cout &lt;&lt; "Eigenvector: " &lt;&lt; V &lt;&lt; std::endl;

        }

    }

}

void TestJacobi(void)

    // 1. P120 Example 5:

    math_Matrix A1(1, 2, 1, 2, 0.0);

    A1(1, 1) = 3.0;  A1(1, 2) = -1.0;

    A1(2, 1) = -1.0; A1(2, 2) = 3.0;

    EvalEigenvalue(A1);

    // 2. P120 Example 6:

    math_Matrix A2(1, 3, 1, 3, 0.0);

    A2(1, 1) = -1.0; A2(1, 2) = 1.0; A2(1, 3) = 0.0;

    A2(2, 1) = -4.0; A2(2, 2) = 3.0; A2(2, 3) = 0.0;

    A2(3, 1) = 1.0;  A2(3, 2) = 0.0; A2(3, 3) = 2.0;

    EvalEigenvalue(A2);

    // 3. P120 Example 7:

    math_Matrix A3(1, 3, 1, 3, 0.0);

    A3(1, 1) = -2.0; A3(1, 2) = 1.0; A3(1, 3) = 1.0;

    A3(2, 1) = 0.0;  A3(2, 2) = 2.0; A3(2, 3) = 0.0;

    A3(3, 1) = -4.0; A3(3, 2) = 1.0; A3(3, 3) = 3.0;

    EvalEigenvalue(A3);

    // 4. P127 Example 12:

    math_Matrix A4(1, 3, 1, 3, 0.0);

    A4(1, 1) = 0.0;  A4(1, 2) = -1.0; A4(1, 3) = 1.0;

    A4(2, 1) = -1.0; A4(2, 2) = 0.0;  A4(2, 3) = 1.0;

    A4(3, 1) = 1.0;  A4(3, 2) = 1.0;  A4(3, 3) = 0.0;

    EvalEigenvalue(A4);

    // 5. P138 Execise 5(3);

    math_Matrix A5(1, 3, 1, 3, 0.0);

    A5(1, 1) = 1.0; A5(1, 2) = 2.0; A5(1, 3) = 3.0;

    A5(2, 1) = 2.0; A5(2, 2) = 1.0; A5(2, 3) = 3.0;

    A5(3, 1) = 3.0; A5(3, 2) = 3.0; A5(3, 3) = 6.0;

    EvalEigenvalue(A5);

int main(int argc, char* argv[])

    // The Jacobi method to find the eigenvalues and

    // eigenvectors of a real symmetric square matrx.

    // The exception NotSquare is raised if the matrix is not square.

    // No verification that the matrix is really symmetric is done.

    TestJacobi();

    return 0;

計算結果部分如下圖所示:

OpenCascade Eigenvalues and Eigenvectors of Square Matrix

Figure 2.1 Jacobi method Result

3. Conclusion

矩陣的特征值和特征向量的理論能用來求解微分方程組的問題。振動分析、現代控制理論中的數學模型都可歸結為對微分方程組的求解。是以,對特征值和特征向量的數值計算有重要的意義。

OpenCascade中提供了使用Jacobi方法來計算特征值和特征向量的類math_Jacobi。從計算結果可以看出,math_Jacobi隻對對稱方陣的計算結果準确,若不是對稱陣,則計算結果是不準确的。

會使用OpenCascade中現成的算法是一回事,能實作這些算法又是另外一回事。對計算特征值和特征向量的數值方法感興趣的讀者,可以參考《計算方法》或《數值分析》等相關書籍。

4. References

1. 同濟大學應用數學系. 線性代數. 高等教育出版社. 2003

2. 易大義, 沈雲寶, 李有法. 計算方法. 浙江大學出版社. 2002

3. 楊明, 李先忠. 矩陣論. 華中科技大學出版社. 2005