Red de conocimiento informático - Consumibles informáticos - Programación en lenguaje C del método de eliminación gaussiano

Programación en lenguaje C del método de eliminación gaussiano

void gaussj(doble a[], int n, doble b[])

{

int i, j, k, l, ll, irow, icol

Double big,pivinv,dum

int ipiv[50], indxr[50], indxc[50];

for(j = 0; j & lt= n- 1; j++)

{

ipiv[j]= 0;

}

for(I = 0;i< = n -1; i++)

{

grande = 0.0;

for(j = 0; j & lt= n-1; j++)

{

if(ipiv[j]!=1)

{

for(k = 0; k & lt= n -1 ;k++)

{

if(ipiv[k]==0)

{

if(fabs(a [j * n+k])& gt;=grande)

{

grande = fabs(a[j * n+k]);

irow = j;

icol = k;

}

si(ipiv[k]& gt; 1)

{

cout & lt& lt"Matriz Singular";

}

}

}

}

p>

}

ipiv[icol]= ipiv[icol]+1;

if (irow!=icol)

{

for(l = 0; l & lt= n-1; l++)

{

dum =(a[irow * n+l]) ;

p>

a[irow * n+l]= a[icol * n+l];

a[icol * n+l]= dum;

}

dum = b[irow];

b[irow]= b[icol];

b[icol]= dum;

}

indxr[I]= irow;

indxc[I]= icol;

if(a[icol*n+ icol]==0.0 )

{

cout & lt& lt"Matriz singular.

";

}

PIV inv = 1.0/(a[icol * n+icol]);

a[icol * n+icol]= 1.0 ;

for(l = 0; l & lt= n-1; l++)

{

a[icol * n+l]= a[ icol * n+l]* PIV inv;

}

b[icol]= b[icol]* PIV inv;

for(ll = 0 ;ll & lt= n-1;ll++)

{

if (ll!=icol)

{

dum = a[ll * n+icol];

a[ll * n+icol]= 0.0;

for(l = 0; l & lt= n-1; l++)

{

a[ll * n+l]= a[ll * n+l]-a[icol * n+l]* dum;

}

b[ll]= b[ll]-b[icol]* dum;

}

}

}

for(l = n-1; l & lt=0;l -)

{

if(indxr[l]!=indxc[l ])

{

for(k = 0; k & lt= n-1; k++)

{

dum = a[k * n+indxr[l]];

a[k * n+indxr[l]]= a[k * n+indxc[l]];

a[k * n+indxr[l]]= tonto;

}

}

}

}