using System; using System.Collections.Generic; using System.Linq; using System.Text; using L = Science.Mathematics.LinearAlgebra; namespace Strang3Ed.Chapter06.Section4 { public class ExampleA { public ExampleA() { } private string result; public string Result { get { return result; } } public void Compute() { double[,] x = { {2.0, -1.0, 0.0}, {-1.0, 2.0, -1.0}, {0.0, -1.0, 2.0}}; L.SymmetricMatrix A = new L.SymmetricMatrix(x); A.Diagonalize(); result += A.Eigenvalue[0].ToString() + "\r\n"; result += A.Eigenvector[0].ToString() + "\r\n"; result += A.Eigenvalue[1].ToString() + "\r\n"; result += A.Eigenvector[1].ToString() + "\r\n"; result += A.Eigenvalue[2].ToString() + "\r\n"; result += A.Eigenvector[2].ToString() + "\r\n"; double[,] y = { {1.0, -1.0, 0.0, 0.0}, {-1.0, 2.0, -1.0, 0.0}, {0.0, -1.0, 2.0, -1.0}, {0.0, 0.0,-1.0, 1.0}}; L.SymmetricMatrix B = new L.SymmetricMatrix(y); B.Diagonalize(); result += B.Eigenvalue[0].ToString() + "\r\n"; result += B.Eigenvector[0].ToString() + "\r\n"; result += B.Eigenvalue[1].ToString() + "\r\n"; result += B.Eigenvector[1].ToString() + "\r\n"; result += B.Eigenvalue[2].ToString() + "\r\n"; result += B.Eigenvector[2].ToString() + "\r\n"; result += B.Eigenvalue[3].ToString() + "\r\n"; result += B.Eigenvector[3].ToString() + "\r\n"; } } } /* 3.41421356237309 0.5 -0.707106781186547 0.5 2 0.707106781186548 -2.84494650060196E-16 -0.707106781186547 0.585786437626905 0.5 0.707106781186547 0.5 3.41421356237309 -0.270598050073099 0.653281482438188 -0.653281482438188 0.270598050073099 2 -0.5 0.5 0.5 -0.5 0.585786437626905 0.653281482438188 0.270598050073098 -0.270598050073099 -0.653281482438188 -4.56365826911786E-17 -0.5 -0.5 -0.5 -0.499999999999999 */