lolthisiscool

March 11th, 2009, 07:58 AM

Hi, I am new here as well as towards the C programming language.

I have been getting an error as per the thread's title.

LUdecomposition.c: In function ‘main’:

LUdecomposition.c:56: error: expected ‘]’ before ‘:’ token

LUdecomposition.c:56: error: expected ‘]’ before ‘:’ token

The code was copied from another website which makes me rather confused as it should work for most. Anyhow, here's the code.

// Gaussian Elemination

//

// Copyright by mpC team, 1999

//

// http://www.ispras.ru/~cbr

// mpc@ispras.ru

//

// Version with variable matrix size

#include<stdio.h>

void init_matrix(int dim, double (*a) [dim][dim]) {

int i,j;

for(i=0;i<dim;i++)

for(j=0;j<dim;j++)

(*a)[i][j]=10.;

for(i=0;i<dim;i++)

(*a)[i][i]=10. * dim;

}

void print_matrix(int dim,double (*a) [dim][dim]){

int i,j;

for(i=0;i<dim;i++) {

for(j=0;j<dim;j++)

printf("%lf\t",(*a)[i][j]);

printf("\n");

}

}

main()

{

int N;

int i,j;

printf("\nEnter N (matrix dimension): ");

scanf("%d",&N);

{

double A[N][N];

init_matrix(N,&A);

printf("\n Source Matrix :\n");

print_matrix(N,&A);

for(i=0;i<N-1;i++) {

for(j=i+1;j<N;j++) {

double t;

t=A[j][i]/A[i][i];

if(A[j][i]!=0) A[j][i:N-1]-=t*A[i][i:N-1];

}

}

printf("\n Matrix after LU transformation: \n");

print_matrix(N,&A);

}

}

Thank you!

I have been getting an error as per the thread's title.

LUdecomposition.c: In function ‘main’:

LUdecomposition.c:56: error: expected ‘]’ before ‘:’ token

LUdecomposition.c:56: error: expected ‘]’ before ‘:’ token

The code was copied from another website which makes me rather confused as it should work for most. Anyhow, here's the code.

// Gaussian Elemination

//

// Copyright by mpC team, 1999

//

// http://www.ispras.ru/~cbr

// mpc@ispras.ru

//

// Version with variable matrix size

#include<stdio.h>

void init_matrix(int dim, double (*a) [dim][dim]) {

int i,j;

for(i=0;i<dim;i++)

for(j=0;j<dim;j++)

(*a)[i][j]=10.;

for(i=0;i<dim;i++)

(*a)[i][i]=10. * dim;

}

void print_matrix(int dim,double (*a) [dim][dim]){

int i,j;

for(i=0;i<dim;i++) {

for(j=0;j<dim;j++)

printf("%lf\t",(*a)[i][j]);

printf("\n");

}

}

main()

{

int N;

int i,j;

printf("\nEnter N (matrix dimension): ");

scanf("%d",&N);

{

double A[N][N];

init_matrix(N,&A);

printf("\n Source Matrix :\n");

print_matrix(N,&A);

for(i=0;i<N-1;i++) {

for(j=i+1;j<N;j++) {

double t;

t=A[j][i]/A[i][i];

if(A[j][i]!=0) A[j][i:N-1]-=t*A[i][i:N-1];

}

}

printf("\n Matrix after LU transformation: \n");

print_matrix(N,&A);

}

}

Thank you!