// 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); }
public matrix permute(matrix M, Permutation p) { matrix Ci = generateC(p.ToArray()); /* matrix tmp = problem.getU().transpose() * Ci * problem.getU(); */ matrix tmp = problem.getU() * Ci * problem.getUInverse(); matrix T = new matrix(M.rows, M.cols); for (int i = 0; i < M.rows; i++) { for (int j = 0; j < M.cols; j++) { T[i, j] = tmp[i, j]; } } matrix result = T * M * T.transpose(); return(result); }