public void LinearAlgebraComplexMatrix() { //using DotNumerics.LinearAlgebra; //using DotNumerics; ComplexMatrix A = new ComplexMatrix(3, 3); A[0, 0] = new Complex(3, 9); A[0, 1] = new Complex(4, 6); A[0, 2] = new Complex(1, 8); A[1, 0] = new Complex(8, 3); A[1, 1] = new Complex(2, 4); A[1, 2] = new Complex(5, 5); A[2, 0] = new Complex(2, 5); A[2, 1] = new Complex(7, 2); A[2, 2] = new Complex(5, 5); EigenSystem es = new EigenSystem(); ComplexMatrix eigenvectors; ComplexMatrix eigenvalues = es.GetEigenvalues(A, out eigenvectors); //Ax-lX=0 Complex lambda = eigenvalues[0, 0]; ComplexVector X = eigenvectors.GetColumnVectors()[0]; ComplexMatrix AXmlambdaX = A * X - lambda * X; ObjectDumper.Write("A="); ObjectDumper.Write(A.MatrixToString("0.000")); ObjectDumper.Write("Eigenvalues:"); ObjectDumper.Write(eigenvalues.MatrixToString("0.000")); ObjectDumper.Write("Eigenvectors:"); ObjectDumper.Write(eigenvectors.MatrixToString("0.000")); ObjectDumper.Write("A * X - lambda * X = "); ObjectDumper.Write(AXmlambdaX.MatrixToString("0.000")); }
public void LinearAlgebraEigenvaluesAndEigenvectors() { //using DotNumerics.LinearAlgebra; //using DotNumerics; Matrix A = new Matrix(3, 3); A[0, 0] = 2; A[0, 1] = 5; A[0, 2] = 3; A[1, 0] = 1; A[1, 1] = 5; A[1, 2] = 7; A[2, 0] = 8; A[2, 1] = 2; A[2, 2] = 3; EigenSystem es = new EigenSystem(); ComplexMatrix eigenvectors; ComplexMatrix eigenvalues = es.GetEigenvalues(A, out eigenvectors); //Ax-lX=0 Complex lambda = eigenvalues[0, 0]; ComplexVector X = eigenvectors.GetColumnVectors()[0]; ComplexMatrix AXmlambdaX = A.CopyToComplex() * X - lambda * X; ObjectDumper.Write("A="); ObjectDumper.Write(A.MatrixToString("0.000")); ObjectDumper.Write("Eigenvalues:"); ObjectDumper.Write(eigenvalues.MatrixToString("0.000")); ObjectDumper.Write("Eigenvectors:"); ObjectDumper.Write(eigenvectors.MatrixToString("0.000")); ObjectDumper.Write("A * X - lambda * X = "); ObjectDumper.Write(AXmlambdaX.MatrixToString("0.000")); }
static void Main(string[] args) { GraphLoader loader = new GraphLoader("completPartite.xml"); loader.Init(); Graph graph = loader.GetGraph(); //graph.PrintVertex(); //graph.PrintEdge(); Matrix A = graph.GetAdjacentMatrix(); Matrix D = graph.GetDegreeMatrix(); Console.WriteLine("ADJACENT MATRIX:"); Console.WriteLine(A.MatrixToString()); Console.WriteLine("DEGREE MATRIX:"); Console.WriteLine(D.MatrixToString()); Matrix L = D.Subtract(A); Console.WriteLine("LAPLACIAN MATRIX:"); Console.WriteLine(L.MatrixToString()); EigenSystem eigSys = new EigenSystem(); ComplexMatrix eigenVals = eigSys.GetEigenvalues(L); Console.WriteLine("EIGENVALUES:"); Console.WriteLine(eigenVals.MatrixToString()); GraphPlotter plotter = new GraphPlotter(graph); plotter.Draw(); return; }
public void Schrodinger(double step, double range) { int size = (int)(range / step); EkMatrix = new SymmetricBandMatrix(size, 1); VMatrix = new SymmetricBandMatrix(size, 1); HMatrix = new SymmetricBandMatrix(size, 1); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { // EkMatrix if (i == j) { EkMatrix[i, j] = -2 * C / (step * step * 1e-18); } else if (Math.Abs(i - j) == 1) { EkMatrix[i, j] = 1 * C / (step * step * 1e-18); } else { EkMatrix[i, j] = 0; } //VMatrix if (i == j && (j < (size - Width / step) / 2 || j > (size + Width / step) / 2)) { VMatrix[i, j] = BarrierHeight * e; } else { VMatrix[i, j] = 0; } } } HMatrix = EkMatrix + VMatrix; EigenSystem eigenSystem = new EigenSystem(); eigenVals = eigenSystem.GetEigenvalues(HMatrix, out eigenVects); eigenVals.MultiplyInplace(1 / e); VMatrix.MultiplyInplace(1 / e); EkMatrix.MultiplyInplace(1 / e); HMatrix.MultiplyInplace(1 / e); }
/// <summary> /// Computes a 2D harmonic oscillator wavefunction with given quantum numbers. /// </summary> public static WaveFunction2D1P GetSHOWaveFunction( int gridSizeX, int gridSizeY, float latticeSpacing, float mass, Vec2 packetCenter, float sigma, int N, int Lz, bool multiThread = true) { // Check the input if ((N < 0) || (Lz > N) || (Lz < -N) || ((N + Lz) % 2) != 0) { throw new ArgumentException("Invalid (N,m) in WaveFunctionUtils.GetSHOWaveFunction."); } EigenSystem hamX = Diagonalized1dShoHamiltonian(mass, sigma, packetCenter.X, latticeSpacing, gridSizeX); EigenSystem hamY = Diagonalized1dShoHamiltonian(mass, sigma, packetCenter.Y, latticeSpacing, gridSizeY); Vector eivcX0 = hamX.EigenVector(0); Vector eivcY0 = hamY.EigenVector(0); WaveFunction2D1P result; if ((N == 0) && (Lz == 0)) { result = DirectProduct(hamX.EigenVector(0), hamY.EigenVector(0), latticeSpacing); } else if ((N == 1) && (Lz == 1)) { WaveFunction2D1P psi_10 = DirectProduct(hamX.EigenVector(1), hamY.EigenVector(0), latticeSpacing); WaveFunction2D1P psi_01 = DirectProduct(hamX.EigenVector(0), hamY.EigenVector(1), latticeSpacing); result = psi_10 + Complex.I * psi_01; } else if ((N == 2) && (Lz == 0)) { WaveFunction2D1P psi_20 = DirectProduct(hamX.EigenVector(2), hamY.EigenVector(0), latticeSpacing); WaveFunction2D1P psi_02 = DirectProduct(hamX.EigenVector(0), hamY.EigenVector(2), latticeSpacing); result = psi_20 + psi_02; } else if ((N == 2) && (Lz == 2)) { WaveFunction2D1P psi_11 = DirectProduct(hamX.EigenVector(1), hamY.EigenVector(1), latticeSpacing); WaveFunction2D1P psi_20 = DirectProduct(hamX.EigenVector(2), hamY.EigenVector(0), latticeSpacing); WaveFunction2D1P psi_02 = DirectProduct(hamX.EigenVector(0), hamY.EigenVector(2), latticeSpacing); result = psi_20 - psi_02 + (Math.Sqrt(2) * Complex.I) * psi_11; } else { throw new ArgumentException("Invalid (N,Lz) in WaveFunctionUtils.GetSHOWaveFunction."); } result.Normalize(); return(result); }
public void LinearAlgebraEigenvalues() { //using DotNumerics.LinearAlgebra; //using DotNumerics; Matrix A = new Matrix(3, 3); A[0, 0] = 2; A[0, 1] = 5; A[0, 2] = 3; A[1, 0] = 1; A[1, 1] = 5; A[1, 2] = 7; A[2, 0] = 8; A[2, 1] = 2; A[2, 2] = 3; EigenSystem es = new EigenSystem(); ComplexMatrix eigenvalues = es.GetEigenvalues(A); ObjectDumper.Write("A="); ObjectDumper.Write(A.MatrixToString("0.000")); ObjectDumper.Write("Eigenvalues:"); ObjectDumper.Write(eigenvalues.MatrixToString("0.000")); }