HI everybody, I was trying to use the following code to invert a matrix, everytime I try to run this code, the only error msg that comes up is
'' inv030710.c:83: error: expected initializer before ‘int’ '' in this line of the code
void Gauss( RK8** a, RK8 ** b, int n)
int main()
{
I do not really understand the problem, can you please let me know how to sort out this probleml.
thank you alla nd looking forward to hearing from you.
'' inv030710.c:83: error: expected initializer before ‘int’ '' in this line of the code
void Gauss( RK8** a, RK8 ** b, int n)
int main()
{
I do not really understand the problem, can you please let me know how to sort out this probleml.
thank you alla nd looking forward to hearing from you.
Code:
# include <stdio.h>
#include<malloc.h>
#include<stdio.h>
#include<stdlib.h>
#include <time.h>
# include <string.h>
# include <math.h>
# define RK8 double
void nrerror(char error_text[] )
{
fprintf(stderr,"Numerical Recipes run-time error...\n");
fprintf(stderr,"%s\n",error_text);
fprintf(stderr,"...now exiting to system...\n");
exit(1);
}
double *dvector( int nl,int nh)
{
double *v;
v=(double *)malloc((unsigned) (nh-nl+1)*sizeof(double));
if (!v) nrerror("allocation failure in dvector()");
return v-nl;
}
void free_dvector(double *v,int nl,int nh)
{
free((char*) (v+nl));
nh++;
}
double **dmatrix( int nrl, int nrh, int ncl, int nch )
{
int i;
double **m;
m=(double **) malloc((unsigned) (nrh-nrl+1)*sizeof(double*));
if (!m) nrerror("allocation failure 1 in dmatrix()");
m -= nrl;
for(i=nrl;i<=nrh;i++)
{
m[i]=(double *) malloc((unsigned) (nch-ncl+1)*sizeof(double));
if (!m[i]) nrerror("allocation failure 2 in dmatrix()");
m[i] -= ncl;
}
return m;
}
void free_dmatrix( double **m, int nrl, int nrh, int ncl, int nch )
{
int i;
for(i = nrh;i >= nrl; i--) free((char*) (m[i]+ncl));
free((char*) (m+nrl));
};
void Gauss( RK8** a, RK8 ** b, int n)
int main()
{
double **first;
first = dmatrix( 0, 2, 0, 2 );
double **second;
second = dmatrix( 0, 2, 0, 2 );
first[3][3]={{1.,2.,6.},{3.,4., 5.},{3.,4.,7.}};
second[3][3]={{0.,0.,0.},{0.,0., 0.},{0.,0.,0.}};
Gauss( first , second , 3);
}
void Gauss (RK8 ** a, RK8 ** b, int n)
{
RK8 d, temp = 0, c;
int i, j, k, m, nn, *ipvt;
if ((ipvt = (int *) malloc (n * sizeof (int))) == NULL)
memflt ();
nn = n;
for (i = 0; i < nn; i++)
ipvt[i] = i;
for (k = 0; k < nn; k++)
{
temp = 0.;
m = k;
for (i = k; i < nn; i++)
{
d = a[k][i];
if (fabs (d) > temp)
{
temp = fabs (d);
m = i;
}
}
if (m != k)
{
j = ipvt[k];
ipvt[k] = ipvt[m];
ipvt[m] = j;
for (j = 0; j < nn; j++)
{
temp = a[j][k];
a[j][k] = a[j][m];
a[j][m] = temp;
}
}
d = 1 / a[k][k];
for (j = 0; j < k; j++)
{
c = a[j][k] * d;
for (i = 0; i < nn; i++)
a[j][i] -= a[k][i] * c;
a[j][k] = c;
}
for (j = k + 1; j < nn; j++)
{
c = a[j][k] * d;
for (i = 0; i < nn; i++)
a[j][i] -= a[k][i] * c;
a[j][k] = c;
}
for (i = 0; i < nn; i++)
a[k][i] = -a[k][i] * d;
a[k][k] = d;
}
for (i = 0; i < nn; i++)
memcpy (b[ipvt[i]], a[i], sizeof (RK8) * nn);
free (ipvt);
}
Comment