[sci.math.stat] Need matrix inversion C routine.

vevea@paideia.uchicago.edu (Jack L. Vevea) (04/22/89)

In article <10087@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes:
>In article <5785@cbnews.ATT.COM> wkb@cbnews.ATT.COM (Wm. Keith Brummett) writes:
>>    I have need of a small, fast routine in C language that will invert
>>    matrices of order <= 4.


	While we're on this subject, I have need of a long, slow matrix
inversion routine that is at least callable from C.  I say
"long, slow" because I need something I can apply to matrices with dimension
in the hundreds, so it must be sensitive to the possibility of rounding
error, and pick the optimal pivots.  It would be nice if, in addition, it
could track its own precision in some way.  If anyone could at least point me
in the direction of a good algorithm, I would be eternally grateful.

	(Apologies if this doesn't belong in comp.lang.c)

faustus@dogwood.Berkeley.EDU (Wayne A. Christopher) (04/24/89)

In article <2846@tank.uchicago.edu>, vevea@paideia.uchicago.edu (Jack L. Vevea) writes:
> 	While we're on this subject, I have need of a long, slow matrix
> inversion routine that is at least callable from C.  I say
> "long, slow" because I need something I can apply to matrices with dimension
> in the hundreds, so it must be sensitive to the possibility of rounding
> error, and pick the optimal pivots.

There are a lot of algorithms used to do this sort of thing with sparse
matrices in circuit simulation.  In particular, the Spice 3 circuit
simulator available from Berkeley has a sparse matrix manipulation
package that you could probably use.

	Wayne

kurtk@tekcae.CAX.TEK.COM (Kurt Krueger) (04/24/89)

There are two 'obvious' places to look for code or algorithms:

The Collected Alogrithmns of the ACM  (CACM).  Any technical/college library
	should have this.  The articles usually contain code (but stuff that
	is well known is likely to be in older articles in Fortran or Pascal)
	and references to the algorithmn used.

Any book on numerical methods.

Note:  "C" is not well suited for writing code for dealing with an arbitrary
	2 (or higher) dimension array.  Brush up on your pointers.  You get
	to do the row/column location by hand.  A good source would be old
	Fortran code (Fortran 2 or IBM 1130 Fortran IV) that handles 2-d
	arrays as a strung out 1-d array.

	Another "trick" is to NOT pass a 2-d array, but pass a vector of
	row pointers.  You can then use matrix[row][column] in your function
	as if you have a "real" 2-d array.  But don't expect blinding execution
	speeds.