471,047 Members | 1,197 Online

# inverse of 3X3 matrix 2
hi i want a c program to find the inverse of 3X3 matrix
urgent
i need it
fast
thanks
Jul 18 '06 #1
1 19581 Banfa
9,065 Expert Mod 8TB
Here is some visual basic code that does something similar, see if you can convert and adapt it.

Can you describe the process of inverting a matrix?

Expand|Select|Wrap|Line Numbers
1. Private Function InternalMatrixSolve(ByRef r1() As Double, ByRef r2() As Double, ByVal size%)
2.     Dim Matrix(2, 2) As Double
3.     Dim Vector(2) As Double
4.
5.     Rem Set up the normalised matrix and vector
6.
7.     For y% = 0 To 2
8.         For x% = 0 To 2
9.             Matrix(y%, x%) = 0
10.             For r% = 1 To size
11.                 Matrix(y%, x%) = Matrix(y%, x%) + ((r1(r%) ^ y%) * (r1(r%) ^ x%))
12.             Next
13.         Next
14.
15.         Vector(y%) = 0
16.         For r% = 1 To size
17.             Vector(y%) = Vector(y%) + ((r1(r%) ^ y%) * r2(r%))
18.         Next
19.     Next
20.
21.     For y% = 0 To 2
22.
23.         Rem Get a 1 on the diagonal by dividing through the current line by the diagnoal cell
24.         Divisor# = Matrix(y%, y%)
25.
26.         If Divisor# = 0 Then
27.             InternalMatrixSolve = "MATHS ERROR"
28.             Exit Function
29.         End If
30.
31.         For x% = y% To 2
32.             Matrix(y%, x%) = Matrix(y%, x%) / Divisor#
33.         Next
34.
35.         Vector(y%) = Vector(y%) / Divisor#
36.
37.         Rem get 0s below the current diagonal by taking away multiples of the current line
38.         For y2% = y% + 1 To 2
39.             Multiplier# = Matrix(y2%, y%)
40.             For x% = y% To 2
41.                 Matrix(y2%, x%) = Matrix(y2%, x%) - (Matrix(y%, x%) * Multiplier#)
42.             Next
43.
44.             Vector(y2%) = Vector(y2%) - (Vector(y%) * Multiplier#)
45.         Next
46.     Next
47.
48.     Rem we now have 1s on the diagnoal and )s below the diagonal
49.     Rem need to get 0s above the diagonal
50.
51.     For y% = 2 To 0 Step -1
52.
53.         Rem get 0s above the current diagonal by taking away multiples of the current line
54.         For y2% = y% - 1 To 0 Step -1
55.             Multiplier# = Matrix(y2%, y%)
56.             For x% = y% To 2
57.                 Matrix(y2%, x%) = Matrix(y2%, x%) - (Matrix(y%, x%) * Multiplier#)
58.             Next
59.
60.             Vector(y2%) = Vector(y2%) - (Vector(y%) * Multiplier#)
61.         Next
62.     Next
63.
64.     InternalMatrixSolve = Vector
65. End Function
Jul 18 '06 #2

 6 posts views Thread by vishnu mahendra | last post: by 1 post views Thread by ravleen bindra | last post: by 7 posts views Thread by ajeetbaraskar | last post: by reply views Thread by YUSUF ISIAKA | last post: by 2 posts views Thread by leelaramtenneti | last post: by 2 posts views Thread by leelaramtenneti | last post: by reply views Thread by DarrenWeber | last post: by 3 posts views Thread by aaram81 | last post: by 1 post views Thread by dazzler | last post: by 3 posts views Thread by MarkDoronin | last post: by reply views Thread by sjain6 | last post: by reply views Thread by Trc0g | last post: by reply views Thread by clicknium | last post: by reply views Thread by autodeveloper | last post: by 1 post views Thread by samanthajade | last post: by reply views Thread by Stoney L | last post: by reply views Thread by SwissProgrammer | last post: by 1 post views Thread by exploretech | last post: by