// Calculate matrix element of a coulomb potential given the charges // of the elements public double coulombPotentialEnergy(matrix A, matrix B) { double epsilon_0 = 1; // Unit is set to 1 maight want to make static units /* int N = problem.getNumberOfParticles() - 1; // For easier readability */ int N = problem.getNumberOfParticles(); double result = 0; matrix inverse = new QRdecomposition(A + B).inverse(); // For every particle pair (only counting once) calculate interaction List <Particle> particles = problem.getParticles(); matrix Uinv = problem.getUInverse(); for (int j = 0; j < N; j++) { for (int i = 0; i < j; i++) { double p_ij = 0; for (int k = 0; k < N - 1; k++) { for (int l = 0; l < N - 1; l++) { double b_ijk = Uinv[i, k] - Uinv[j, k]; double b_ijl = Uinv[i, l] - Uinv[j, l]; p_ij += b_ijk * inverse[k, l] * b_ijl; } } /* result += particles[i].getCharge() * particles[j].getCharge() / (4 * Math.PI * epsilon_0) * Math.Sqrt(2 / (p_ij * Math.PI)) * overlapElement(A,B); */ result += particles[i].getCharge() * particles[j].getCharge() * 2.0 / epsilon_0 * Math.Sqrt(1 / (p_ij * Math.PI * 2)) * overlapElement(A, B); } } return(result); }
// Calculates the matrix element for the kinetic energy public double kineticEnergyElement(matrix A, matrix B) { QRdecomposition qr = new QRdecomposition(A + B); matrix inverse = qr.inverse(); matrix tmp = A * inverse * B * problem.getLambda(); return(3.0 / 2.0 * tmp.trace() * overlapElement(A, B)); }
public void Test_inverse() { matrix A = new matrix("1,2,3;0,1,4;5,6,0"); QRdecomposition qr = new QRdecomposition(A); matrix inv = qr.inverse(); matrix inverse = new matrix("-24,18,5;20,-15,-4;-5,4,1"); /* Assert.IsTrue(inv.equals(inverse)); */ // It is true.... Assert.IsTrue(Misc.sortOfEqual(inv, inverse, 8)); }
// Calculate the overlap of two test functions represented by matrices public double overlapElement(matrix A, matrix B) { QRdecomposition qr = new QRdecomposition(A + B); double determinant = 1; for (int i = 0; i < A.cols; i++) { determinant *= qr.R[i, i]; } double nominator = Math.Pow(2 * Math.PI, A.cols); return(Math.Pow(nominator / determinant, 3.0 / 2.0)); }
public void runSymHelium() { double E0 = double.PositiveInfinity; int size = 30; List <matrix> basis = generateTestFunctions(size); List <Permutation> p = new List <Permutation>(); List <int> l1 = new List <int>(); l1.Add(0); l1.Add(1); l1.Add(2); List <int> l2 = new List <int>(); l2.Add(1); l2.Add(0); l2.Add(2); p.Add(new Permutation(l1, 1, 1)); p.Add(new Permutation(l2, -1, 1)); perms = p; for (int k = 0; k < 1000; k++) { for (int i = 0; i < size; i++) { for (int j = 0; j < 100; j++) { List <matrix> tmpbasis = new List <matrix>(basis); tmpbasis[i] = generateA(); if (validateB(generateB2(tmpbasis))) { vector v = new vector(tmpbasis.Count); matrix L = new CholeskyDecomposition(generateB2(tmpbasis)).L; matrix inv = new QRdecomposition(L).inverse(); matrix inv_T = new QRdecomposition(L.transpose()).inverse(); matrix h = generateH2(tmpbasis); matrix m = inv * h * inv_T; jacobi.eigen(m, v); double low = v[0]; if (low < E0) { E0 = low; basis = tmpbasis; Console.WriteLine(E0); if (E0 < -2.2) { h.print(); } } } } } } }
// Calculate eigen values of system as specified in problem public vector eigenValues(List <matrix> testFunctions) { vector v = new vector(testFunctions.Count); /* try { */ matrix H = generateH(testFunctions); matrix B = generateB(testFunctions); matrix L = new CholeskyDecomposition(B).L; matrix inv = new QRdecomposition(L).inverse(); matrix inv_T = new QRdecomposition(L.transpose()).inverse(); matrix p = inv * H * inv_T; jacobi.eigen(p, v); /* } catch (CholeskyException ce) { */ /* Console.WriteLine(ce); */ /* } */ return(v); }
// Generate matrix containing non-linear parameters for the gaussian test // functions transformed to center of mass system /* public matrix generateA() { */ /* matrix A = new matrix(nParticles - 1, nParticles -1); */ /* List<double> alphas = makeAlphas(); */ /* // Generate values for every entry in the matrix A */ /* for (int k = 0; k < nParticles - 1; k++) { */ /* for (int l = 0; l < k; l++) { */ /* double akl = A_kl(k,l,alphas); */ /* A[l,k] = akl; */ /* A[k,l] = akl; */ /* } */ /* A[k,k] = A_kl(k,k,alphas); */ /* } */ /* return A; */ /* } */ public matrix generateA() { matrix A = new matrix(nParticles - 1, nParticles - 1); matrix B = new matrix(A.rows, A.cols); for (int i = 0; i < A.cols; i++) { for (int j = 0; j < A.cols; j++) { if (i == j) { A[i, j] = Math.Log(1 - r.NextDouble()) / -1; } B[i, j] = Math.Log(1 - r.NextDouble()) / -1; } } matrix Q = new QRdecomposition(B).Q; return(Q * A * Q.transpose()); }