Last active
December 23, 2015 17:09
-
-
Save Alrecenk/6666802 to your computer and use it in GitHub Desktop.
Solves for C given an LDL decomposition in the form LDL^T C = X^T Y.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public double[] solvesystem(double L[][], double D[], double XTY[]){ | |
//back substitution with L | |
double p[] = new double[XTY.length] ; | |
for (int j = 0; j < inputs; j++){ | |
p[j] = XTY[j] ; | |
for (int i = 0; i < j; i++){ | |
p[j] -= L[j][i] * p[i]; | |
} | |
} | |
//Multiply by inverse of D matrix | |
double q[] = new double[p.length] ; | |
for (int k = 0; k < inputs; k++){//inverse of diagonal | |
q[k] = p[k]/D[k];//is 1 / each element | |
} | |
// forward substitution with L^T | |
double c[] = new double[q.length]; | |
for (int j = inputs - 1; j >= 0; j--){ | |
c[j] = q[j] ; | |
for (int i = j + 1; i < inputs; i++){ | |
c[j] -= L[i][j] * c[i]; | |
} | |
} | |
return c ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment