wer ajan severim mısır

))şindi o mısırın matrisini ters düz edeyimde gör

mısırda matris enteresan
#define REAL double
double determ_ref;
/*
mısırın tersi alan rutindir bu

))
Bu kod alıntıdır walla

kendi dökümanlarımı bulamadım ama yararlı olur. Mat isimli matrisin tersini alip,
yine Mat içerisine yazar. Boyut mxm olmalidir.
*/
int matrix_inverse(double **Mat, int size)
{
int nrows=size, ncols=size;
double determinant = 1;
const double singularity_tolerance = 1e-35;
// Locations of pivots (indices start with 0)
struct Pivot { int row, col; } * const pivots =
(Pivot*)malloc(ncols*sizeof(Pivot));
bool * const was_pivoted = (bool*)alloca(nrows*sizeof(bool));
for(register int k=0; k<nrows; k++)
was_pivoted[k]=false;
for(register Pivot * pivotp = &pivots[0]; pivotp < &pivots[ncols]; pivotp++)
{
const REAL * old_ppos = 0; // Location of a pivot to be
int prow = 0, pcol = 0; // Pivot's row and column indices
{ // Look through all non-pivoted cols
REAL max_value = 0; // (and rows) for a pivot (max elem)
register const REAL *cp = Mat[0]; // column pointer
for(register int j=0; j<ncols; j++)
if( !was_pivoted[j] )
{ // the following loop would increment
REAL curr_value = 0; // cp by nrows
for(register int k=0; k<nrows; k++,cp++)
if( !was_pivoted[k] && (curr_value = fabs(*cp)) > max_value )
max_value = curr_value, prow = k, pcol = j, old_ppos = cp;
}
else
cp += nrows; // and this branch would too
if( max_value < singularity_tolerance )
{
printf("Matrix turns out to be singular: can't invert\n");
return -1;
}
pivotp->row = prow;
pivotp->col = pcol;
}
REAL * const old_colp = const_cast<REAL*>(old_ppos) - prow;
REAL * const new_colp = ( prow == pcol ? old_colp : Mat[0] + prow*nrows );
if( prow != pcol ) // Swap prow-th and pcol-th columns to
{ // bring the pivot to the diagonal
register REAL * cr = new_colp;
register REAL * cc = old_colp;
for(register int k=0; k<nrows; k++)
{
REAL temp = *cr; *cr++ = *cc; *cc++ = temp;
}
}
was_pivoted[prow] = true;
{ // Normalize the pivot column and
register REAL * pivot_cp = new_colp;
const double pivot_val = pivot_cp[prow]; // pivot is at the diagonal
determinant *= pivot_val; // correct the determinant
pivot_cp[prow] = 1;
for(register int k=0; k<nrows; k++)
*pivot_cp++ /= pivot_val;
}
{ // Perform eliminations
register REAL * pivot_rp = Mat[0] + prow; // pivot row
register REAL * ep = Mat[0]; // sweeps all matrix' columns
for(register int k=0; k<ncols; k++, pivot_rp += nrows)
if( k != prow )
{
const double temp = *pivot_rp;
*pivot_rp = 0;
register const REAL * pivot_cp = new_colp; // pivot column
for(register int l=0; l<nrows; l++)
*ep++ -= temp * *pivot_cp++;
}
else
ep += nrows;
}
}
int no_swaps = 0; // Swap exchanged *rows* back in place
for(register const Pivot * pvp = &pivots[ncols-1];
pvp >= &pivots[0]; pvp--)
if( pvp->row != pvp->col )
{
no_swaps++;
register REAL * rp = Mat[0] + pvp->row;
register REAL * cp = Mat[0] + pvp->col;
for(register int k=0; k<ncols; k++, rp += nrows, cp += nrows)
{
const REAL temp = *rp; *rp = *cp; *cp = temp;
}
}
determ_ref = ( no_swaps & 1 ? -determinant : determinant );
return 0;
}