4 by 4 Matrix Inversion
4 by 4 Matrix Inversion
4 by 4 Matrix Inversion
&
BACKWARD COMPUTATION
Using Visual Basic 6.0
COURSE: SVY 312
BY
GROUP MEMBERS
Name Matric No Obey Ife Akin 060405026 Oluwo Abisoye .I.T 070405027 Ufan Iboro Anietie 060405019 Falade
Introduction
Before we can talk of programming, a certain problem has to exist and in order to solve this problem there are some certain stages which one must go through. These stages include: Existence of a problem to be solved Understanding the problem Planning the solution Preparing flowchart or algorithm Coding Inputting program into the computer Program run and testing Documentation.
We have two problems to be dealt with so we are going to take a look at how these problems can be solved using Visual Basic 6.0 application.
Some Features of Visual Basic include: - Full set of objects - you 'draw' the application - Lots of icons and pictures for your use - Response to mouse and keyboard actions - Clipboard and printer access - Full array of mathematical, string handling, and graphics functions - Can handle fixed and dynamic variable and control arrays - Sequential and random access file support Useful debugger and error-handling facilities Powerful database access tools - ActiveX support - Package & Deployment Wizard makes distributing your applications simple
Application (Project) interface is made up of: a) Forms - Windows that you create for user interface b) Controls - Graphical features drawn on forms to allow user interaction (textboxes, labels, scroll bars, command buttons, etc.) (Forms and Controls are objects.) c) Properties - Every characteristic of a form or control is specified by a property. Example properties include names, captions, size, color, position, and contents. Visual Basic applies default properties. You can change properties at design time or run time. d) Methods - Built-in procedure that can be invoked to impart some action to a particular object. e) Event Procedures - Code related to some object. This is the code that is executed when a certain event occurs.
invoked by the application. g) Modules - Collection of general procedures, variable declarations, and constant definitions used by application.
4 by 4 MATRIX INVERSION
For this particular problem, we used the adjoint/co-factor method to create a program which can be used to solve the 4 by 4 matrix. We started off by creating the user interface which looks like the one below;
Afterwards, we went on to write the codes for the program. The program codes are written below;
Private Sub Command1_Click() Dim a11 As Double, a12 As Double, a13 As Double, a14 As Double, a21 As Double, a22 As Double, a23 As Double, a24 As Double, a31 As Double, a32 As Double, a33 As Double, a34 As Double, a41 As Double, a42 As Double, a43 As Double, a44 As Double Dim b11 As Double, b12 As Double, b13 As Double, b14 As Double, b21 As Double, b22 As Double, b23 As Double, b24 As Double, b31 As Double, b32 As Double, b33 As Double, b34 As Double, b41 As Double, b42 As Double, b43 As Double, b44 As Double Dim detA As Double Dim c11, c12, c13, c14, c21, c22, c23, c24, c31, c32, c33, c34, c41, c42, c43, c44 As Double
a11 = Val(e1.Text)
a12 = Val(e2.Text) a13 = Val(e3.Text) a14 = Val(e4.Text) a21 = Val(e5.Text) a22 = Val(e6.Text) a23 = Val(e7.Text) a24 = Val(e8.Text) a31 = Val(e9.Text) a32 = Val(e10.Text) a33 = Val(e11.Text) a34 = Val(e12.Text) a41 = Val(e13.Text) a42 = Val(e14.Text) a43 = Val(e15.Text) a44 = Val(e16.Text) detA = -a41 * (a12 * ((a23 * a34) - (a24 * a33)) - a13 * ((a22 * a34) - (a24 * a32)) + a14 * ((a22 * a33) - (a23 * a32))) + a42 * (a11 * ((a23 * a34) - (a24 * a33)) - a13 * ((a21 * a34) - (a24 * a31)) + a14 * ((a21 * a33) - (a23 * a31))) - a43 * (a11 * ((a22 * a34) - (a24 * a32)) - a12 * ((a21 * a34) - (a24 * a31)) + a14 * ((a21 * a32) - (a22 * a31))) + a44 * (a11 * ((a22 * a33) - (a23 * a32)) - a12 * ((a21 * a33) - (a23 * a31)) + a13 * ((a21 * a32) - (a22 * a31))) dA.Text = detA
c11 = a22 * ((a33 * a44) - (a43 * a34)) - a23 * ((a32 * a44) - (a34 * a42)) + a24 * ((a32 * a43) - (a33 * a42))
c12 = -(a21 * ((a33 * a44) - (a34 * a43)) - a23 * ((a31 * a44) - (a41 * a34)) + a24 * ((a31 * a43) - (a33 * a41))) c13 = a21 * ((a32 * a44) - (a34 * a42)) - a22 * ((a31 * a44) - (a41 * a34)) + a24 * ((a31 * a42) - (a32 * a41)) c14 = -(a21 * ((a32 * a43) - (a33 * a42)) - a22 * ((a31 * a43) - (a41 * a33)) + a23 * ((a31 * a42) - (a32 * a41)))
c21 = -(a12 * ((a33 * a44) - (a43 * a34)) - a13 * ((a32 * a44) - (a34 * a42)) + a14 * ((a32 * a43) - (a42 * a33))) c22 = a11 * ((a33 * a44) - (a43 * a34)) - a13 * ((a31 * a44) - (a34 * a41)) + a14 * ((a31 * a43) - (a41 * a33)) c23 = -(a11 * ((a32 * a44) - (a42 * a34)) - a12 * ((a31 * a44) - (a34 * a41)) + a14 * ((a31 * a42) - (a41 * a32))) c24 = a11 * ((a32 * a43) - (a33 * a42)) - a12 * ((a31 * a43) - (a33 * a41)) + a13 * ((a31 * a42) - (a32 * a41))
c31 = a12 * ((a23 * a44) - (a43 * a24)) - a13 * ((a22 * a44) - (a42 * a24)) + a14 * ((a22 * a43) - (a42 * a23)) c32 = -(a11 * ((a23 * a44) - (a43 * a24)) - a13 * ((a21 * a44) - (a41 * a24)) + a14 * ((a21 * a43) - (a41 * a23))) c33 = a11 * ((a22 * a44) - (a42 * a24)) - a12 * ((a21 * a44) - (a41 * a24)) + a14 * ((a21 * a42) - (a41 * a22)) c34 = -(a11 * ((a22 * a43) - (a42 * a23)) - a12 * ((a21 * a43) - (a41 * a23)) + a13 * ((a21 * a42) - (a22 * a41)))
c41 = -(a12 * ((a23 * a34) - (a33 * a24)) - a13 * ((a22 * a34) - (a32 * a24)) + a14 * ((a22 * a33) - (a32 * a23))) c42 = a11 * ((a23 * a34) - (a33 * a24)) - a13 * ((a21 * a34) - (a31 * a24)) + a14 * ((a21 * a33) - (a31 * a23))
c43 = -(a11 * ((a22 * a34) - (a32 * a24)) - a12 * ((a21 * a34) - (a31 * a24)) + a14 * ((a21 * a32) - (a31 * a22))) c44 = a11 * ((a22 * a33) - (a32 * a23)) - a12 * ((a21 * a33) - (a31 * a23)) + a13 * ((a21 * a32) - (a31 * a22))
b11 = c11 / detA b12 = c12 / detA b13 = c13 / detA b14 = c14 / detA b21 = c21 / detA b22 = c22 / detA b23 = c23 / detA b24 = c24 / detA b31 = c31 / detA b32 = c32 / detA b33 = c33 / detA b34 = c34 / detA b41 = c41 / detA b42 = c42 / detA b43 = c43 / detA b44 = c44 / detA
d3.Text = b31 d4.Text = b41 d5.Text = b12 d6.Text = b22 d7.Text = b32 d8.Text = b42 d9.Text = b13 d10.Text = b23 d11.Text = b33 d12.Text = b43 d13.Text = b14 d14.Text = b24 d15.Text = b34 d16.Text = b44
End Sub
Private Sub Command2_Click() e1.Text = "" e2.Text = "" e3.Text = "" e4.Text = "" e5.Text = ""
e6.Text = "" e7.Text = "" e8.Text = "" e9.Text = "" e10.Text = "" e11.Text = "" e12.Text = "" e13.Text = "" e14.Text = "" e15.Text = "" e16.Text = "" d1.Text = "" d2.Text = "" d3.Text = "" d4.Text = "" d5.Text = "" d6.Text = "" d7.Text = "" d8.Text = "" d9.Text = "" d10.Text = "" d11.Text = "" d12.Text = ""
d13.Text = "" d14.Text = "" d15.Text = "" d16.Text = "" dA.Text = ""
End Sub
20 Calculate the minor of each of the following elements ( i.e. a11,a12...a44) by finding the determinant of the 3 by 3 matrix 30 Calculate the cofactor of the different elements of the rows and columns and apply the necessitated symbols in front of each of them. 40 50 60 Transpose the cofactor to obtain the adjoint Calculate the determinant Divide the adjoint by the determinant to obtain the inverse matrix.
Step by step understanding of the methodology involved Straightforwardness of the method of solution
Some of the deficiencies attached to this method of solution are; It is cumbersome to calculate. It is time-taking and could be really confusing if one is not careful.
BACKWARD COMPUTATION
Backward computation is a method used in solving traverse problems. This problem is not as cumbersome as the 4 by 4 matrix inversion problem although it involves the use of additional functions such as sine, cosine, etc. As usual, we start off with the designing of the user interface which is shown below:
We then write the codes for the program after the algorithm has been studied carefully by the program writer. The program codes are written below;
Private Sub Command1_Click() Dim x1, y1, x2, y2 As Double Dim dy, dx, length, Bearing, TrueBearing, departure, latitude, dist As Double
dy = y2 - y1
dx = x2 - x1
dist = Sqr(dy ^ 2 + dx ^ 2)
Distance.Text = dist
If (dx > 0 And dy > 0) Then Bearing = (Atn(dx / dy)) * (180 / (4 * Atn(1))) TrueBearing = Bearing
ElseIf (dx > 0 And dy < 0) Then Bearing = (Atn(dx / dy)) * (180 / (4 * Atn(1))) TrueBearing = 180 + Bearing
ElseIf (dx < 0 And dy < 0) Then Bearing = (Atn(dx / dy)) * (180 / (4 * Atn(1))) TrueBearing = 180 + Bearing
ElseIf (dx < 0 And dy > 0) Then Bearing = (Atn(dx / dy)) * (180 / (4 * Atn(1))) TrueBearing = 360 + Bearing
ElseIf (dx = 0 And dy < 0) Then Bearing = (Atn(dx / dy)) * (180 / (4 * Atn(1))) TrueBearing = 180
End If
text6.Text = TrueBearing
End Sub
Private Sub Command3_Click() p1x.Text = "" p2x.Text = "" p1y.Text = "" p2y.Text = "" Distance.Text = "" text6.Text = "" Text1.Text = "" Text2.Text = "" End Sub
40 50
60 Let distance = sqr(E2 + N2) 70 80 90 If E > 0 and N > 0 then bearing AB = {deg} If E > 0 and N < 0 then bearing AB = 180 - {deg} If E < 0 and N > 0 then bearing AB = 360 - {deg}
100 If E < 0 and N < 0 then bearing AB = 180 + {deg} 110 If E = 0 and N > 0 then bearing AB = 0 120 If E = 0 and N < 0 then bearing AB = 180 130 If E = 0 and N > 0 then bearing AB = 90 140 If E = 0 and N = 0 then bearing AB = 360 150 Print distance and bearing AB 160 If AB < 180 then bearing BC = bearing AB + 180 + 170 If AB > 180 then bearing BC = bearing AB - 180 + 180 If AB > 360 then bearing BC = bearing BC 360 190 Print bearing BC
Some of the highlights to look out for include; - The conversion of the bearings from radians to degrees - The negative and positive signs in front of the coordinates or other parameters.
The above shows the program interface with the required inputs only. It is only after the inputs must have been keyed in that we can then click on the calculate button in order to get our output. It is shown below;