Code to inverse a matrix

Discussion in 'Programmer's Corner' started by blindoffaith, Aug 22, 2005.

1. blindoffaith Thread Starter New Member

Aug 22, 2005
4
0
Hi
This is my first post here so enjoy I'm looking for a code that obtains the inverted matrix of a given matrix
using the Gaussian elimination method ( http://en.wikipedia.org/wiki/Gaussian_elimination)

the code is found on the bottom of the page linked above :

i=1
j=1
while (i ≤ m and j ≤ n) do
# Find pivot in column j, starting in row i:
max_val = A[i,j]
max_ind = i
for k=i+1 to m do
val = A[k,j]
if abs(val) > abs(max_val) then
max_val = val
max_ind = k
end_if
end_for
if max_val ≠ 0 then
switch rows i and max_ind
divide row i by max_val
for u = 1 to m do
if u ≠ i then
add - A[u,j] * row i to row u
end_if
end_for
i = i + 1
end_if
j = j + 1
end_while

this code seems to work but not quite well or i have trouble doing it right .

also i'm interested in other source codes for matrix inverting .
i tried to work with this one because it's probably the fastest.

2. aibelectronics Member

Aug 26, 2005
24
0
Where does the code not work well? I think if you told us where it starts behaving erratically we'll find it easier debugging it.
would the language we use for the source code matter? personally i use c & fortran I don't know if you'll have problems with them?

3. blindoffaith Thread Starter New Member

Aug 22, 2005
4
0
thanks for the help but i've figured it out by now . ..
i mean it really works.