I need help with writing an inverse() function....any one got a clue?
Gauss Jordan function????
Collapse
X
-
I take it you're writing a function to calculate the mathematical inverse. If you posted the formula for that, we could help you create an algorithm for programming it.Originally posted by kaygeeI need help with writing an inverse() function....any one got a clue? -
5 Description of the AlgorithmOriginally posted by cyberkingHi.
If its a mathematical inverse u are tryin, then this would be the code of the function..
int inverse(number_ from_main)
{
int inverse; // can also be float
inverse = 1 / number_from_mai n ;
return inverse;
}
Algorithm 5.1: Gauss-Jordan Method (B 2 <n×n)
comment: Create an Augmented Matrix
A = [B I]
for i = 1 to n
8>
>>>>>>>>>>>>>>> >>>>>>>>>>>><>> >>>>>>>>>>>>>>> >>>>>>>>>>>:
comment: Find the pivot
pivot aii
if pivot < 10−8
then
8>
>><>>>:
Matrix is singular
det 0
Return
comment: Perform Row Elimination
comment: Normalise the row by dividing each element by the pivot
for j = 1 to 2n
aij = aij/pivot
for k = 1 to n
8>
>>>>>><>>>>>> >:
if k 6= i
then
8>
>><>>>:
m aki
for j = 1 to 2n
akj = akj − m × aij
for i = 1 to n
8>
<>
:
for j = 1 to n
B−1[i, j] = A[i, j + n]
output (B−1)Comment
Comment