From 3a22d644da666c934c4cf218687da5814c7b43bb Mon Sep 17 00:00:00 2001 From: Georg Holzmann Date: Mon, 15 Jan 2007 20:06:42 +0000 Subject: small fix svn path=/trunk/externals/iem/iemmatrix/; revision=7338 --- src/iemmatrix_utility.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++ src/mtx_inverse.c | 66 ------------------------------ src/mtx_mul.c | 17 -------- src/mtx_transpose.c | 14 ------- 4 files changed, 104 insertions(+), 97 deletions(-) (limited to 'src') diff --git a/src/iemmatrix_utility.c b/src/iemmatrix_utility.c index 0781226..553e308 100644 --- a/src/iemmatrix_utility.c +++ b/src/iemmatrix_utility.c @@ -416,3 +416,107 @@ void matrix_free(t_matrix *x) x->atombuffer=0; x->col=x->row=0; } + + +/* some math */ + +/* invert a square matrix (row=col=rowcol) */ +/* if "error" is non-NULL, it's content will be set to 0 if the matrix was invertable, else to non-0 */ +t_matrixfloat* mtx_doInvert(t_matrixfloat*input, int rowcol, int*err){ + /* + * row==col==rowclo + * input=t_matrixfloat[row*col] + * output=t_matrixfloat[row*col] + */ + int i, k; + t_matrixfloat *a1, *b1, *a2, *b2; + + int ok=0; /* error counter */ + + int col=rowcol, row=rowcol, row2=row*col; + t_matrixfloat *original=input; + t_matrixfloat *inverted = 0; + + if(input==0)return 0; + + /* 1a reserve space for the inverted matrix */ + inverted=(t_matrixfloat *)getbytes(sizeof(t_matrixfloat)*row2); + if(inverted==0)return 0; + + /* 1b make an eye-shaped float-buf for B */ + i=row2; + b1=inverted; + while(i--)*b1++=0; + i=row; + b1=inverted; + while(i--)b1[i*(row+1)]=1; + + /* 2. do the Gauss-Jordan */ + for (k=0;k