Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / June 2005



Tip: Looking for answers? Try searching our database.

3x3 matrices division

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Noa - 27 Jun 2005 20:29 GMT
Hi, University was a long time ago and I haven't used linear algebra
since...
Can someone be kind and describe how do I divide a 3x3 by another 3x3
matrix (in order to get a 1x3 vector)?
I need to write a simple code that uses this algorithm and (AFAIK)
there are no internal matrix functions in vb6.
Thx, Dan.
Randy Day - 28 Jun 2005 00:48 GMT
> Hi, University was a long time ago and I haven't used linear algebra
> since...
[quoted text clipped - 3 lines]
> there are no internal matrix functions in vb6.
> Thx, Dan.

The last example on this page touches on it:

http://www.biomechanics.psu.edu/tutorials/Kin_tutor04.html

HTH
Michael Harrington - 28 Jun 2005 06:10 GMT
I think you need to know how to invert the matrix
and also find the determinant. Here is a demo on the
latter. I'll dust off the old algebra books and see if I
can do an inversion.

Option Explicit
'Determinant of 3x3 matrix

Private Sub Command1_Click()
Dim matrix(1 To 3, 1 To 3) As Double

matrix(1, 1) = 1
matrix(1, 2) = 2
matrix(1, 3) = 0

matrix(2, 1) = -1
matrix(2, 2) = 1
matrix(2, 3) = 1

matrix(3, 1) = 1
matrix(3, 2) = 2
matrix(3, 3) = 5

Print Determinant(matrix)

End Sub

Function Determinant(M() As Double) As Double

Determinant = M(1, 1) * (M(2, 2) * M(3, 3) - M(2, 3) * M(3, 2)) _
        - M(1, 2) * (M(2, 1) * M(3, 3) - M(2, 3) * M(3, 1)) _
        + M(1, 3) * (M(2, 1) * M(3, 2) - M(2, 2) * M(3, 1))

End Function

> Hi, University was a long time ago and I haven't used linear algebra
> since...
[quoted text clipped - 3 lines]
> there are no internal matrix functions in vb6.
> Thx, Dan.
spacewarp - 28 Jun 2005 19:59 GMT
Below is some code that inverses a 3 x 3 matrix. Note that the
matrices' are 1-based in my example below.
(Mind the word wraps)

Option Explicit

' This function returns the determinant of a 2 x 2 matrix
'     a   b
'     c   d
Private Function Det2D(a As Double, b As Double, c As Double, d As
Double) As Double
   Det2D = a * d - b * c
End Function

' This function returns the determinant of a 3 x 3 matrix
Private Function Determinant(M() As Double) As Double
   Determinant = M(1, 1) * (M(2, 2) * M(3, 3) - M(2, 3) * M(3, 2)) _
               - M(1, 2) * (M(2, 1) * M(3, 3) - M(2, 3) * M(3, 1)) _
               + M(1, 3) * (M(2, 1) * M(3, 2) - M(2, 2) * M(3, 1))
End Function

' This function returns the Inverse of a 3 x 3 matrix
Private Function Inverse(M() As Double) As Double()
   Dim det As Double
   det = Determinant(M)

   If det = 0 Then
       ' Handle the error as you wish ...
       MsgBox "Inversion error! Matrix is singular and thus
non-invertible"
       Exit Function
   End If

   Dim I(1 To 3, 1 To 3) As Double
   I(1, 1) = Det2D(M(2, 2), M(2, 3), M(3, 2), M(3, 3)) / det
   I(1, 2) = -Det2D(M(1, 2), M(1, 3), M(3, 2), M(3, 3)) / det
   I(1, 3) = Det2D(M(1, 2), M(1, 3), M(2, 2), M(2, 3)) / det
   I(2, 1) = -Det2D(M(2, 1), M(2, 3), M(3, 1), M(3, 3)) / det
   I(2, 2) = Det2D(M(1, 1), M(1, 3), M(3, 1), M(3, 3)) / det
   I(2, 3) = -Det2D(M(1, 1), M(2, 1), M(1, 3), M(2, 3)) / det
   I(3, 1) = Det2D(M(2, 1), M(2, 2), M(3, 1), M(3, 2)) / det
   I(3, 2) = -Det2D(M(1, 1), M(1, 2), M(3, 1), M(3, 2)) / det
   I(3, 3) = Det2D(M(1, 1), M(1, 2), M(2, 1), M(2, 2)) / det

   Inverse = I
End Function

' Invert a matrix when the form loads and display the results
' in the Immediate pane
Private Sub Form_Load()
   Dim M(1 To 3, 1 To 3) As Double
   Dim I() As Double

   M(1, 1) = 1
   M(1, 2) = 3
   M(1, 3) = 3
   M(2, 1) = 1
   M(2, 2) = 4
   M(2, 3) = 3
   M(3, 1) = 1
   M(3, 2) = 3
   M(3, 3) = 4

   I = Inverse(M)

   Debug.Print I(1, 1), I(1, 2), I(1, 3)
   Debug.Print I(2, 1), I(2, 2), I(2, 3)
   Debug.Print I(3, 1), I(3, 2), I(3, 3)
End Sub

With the inversion done, it is a simple problem of multiplying the
inverse matrix with another matrix to get the result. The
multiplication part is left as an exercise to the reader ... ;-)

Hope this helps.
Suresh
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.