Skip to content

Instantly share code, notes, and snippets.

@Alrecenk
Last active December 23, 2015 17:09
Show Gist options
  • Save Alrecenk/6666802 to your computer and use it in GitHub Desktop.
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.
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