I'm having trouble with this function. It's a LU factorization program. I'm trying to read columns instead of rows because I wanna put the elements of the array b there. If you could help me, I'd be thankful.
void lower(int N, double *b){
int i, j, k, Z=0;
double **L;
L = (double **) calloc(N, sizeof(double*));
for(i=0; i<N; i++){
L[i] = (double *) calloc(N, sizeof(double));
for(j=0; j<N; j++){
for(k=i; k<N; k++){
if(k > j){
L[k][j] = b[Z];
Z++;
}
else if (k == j)
L[k][j] = 1;
}
}
}
print_matriz(N, L);
free(L);}
If I do this:
`for(i=0; i<N; i++){
L[i] = (double *) calloc(N, sizeof(double));
for(j=0; j<N; j++){
if(i > j){
L[i][j] = b[Z];
Z++;
}
else if(i == j)
L[i][j] = 1;
}
}`
I get these results below: I'm trying to make a matrix like this (example):
1 0 0 0
2 1 0 0
3 5 1 0
4 6 7 1
But instead, I'm getting this:`
1 0 0 0
2 1 0 0
3 4 1 0
5 6 7 1
`