On 2006-05-12,
ro**********@gmail.com <ro**********@gmail.com> wrote:
[
kumar> i request the group to please send me " c programs " to find the
kumar> matrix inverse and determinant for any order.
]
Why? I am sure you can find some open-source software that has the two
operations you are looking for. The determinant is very easy to
implement using a recursive algorithm.
The recursive algorithm is easy to implement, but likely to be very
inefficient if the number of rows and columns is much more than 4.
One way to work out the determinant I've heard of is to make the matrix
upper-triangular, and then to multiply all the diagonal elements
together.
The upper-triangular matrix can also be used to invert the matrix.
I have some octave source to hand for this, which could be converted to
C fairly easily, if the OP can understand the octave. Doesn't include
solving for the inverse using U, but that part isn't too hard.
1;
function U = gauss(M)
% Make a matrix upper triangular
for i = 2:rows(M)
for j = 1:i - 1 % rows above you
f = M(i, j) / M(j, j);
M(i, :) -= M(j, :) * f;
endfor
endfor
U = M;
endfunction
function d = my_det(M)
% Compute determinant using Gaussian elimination followed by multiplying
% diagonal elements together
U = gauss(M);
d = 1;
for i = 1:rows(U)
d *= U(i, i);
endfor
endfunction
M = rand(6)
% Using built-in det
det(M)
% Using our one, for comparison
my_det(M)