You are on page 1of 22

4 by 4 MATRIX INVERSION

&
BACKWARD COMPUTATION
Using Visual Basic 6.0
COURSE: SVY 312

COURSE TITLE: COMPUTER APPLICATIONS IN SURVEYING

BY

GROUP Lecturer: BADEJO (DR)


October, 2009

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.

ABOUT Visual Basic 6.0


Visual Basic is a tool that allows you to develop Windows (Graphic User Interface - GUI) applications. The applications have a familiar appearance to the user. Visual Basic is an object-oriented programming development system for creating applications that run under any of the Microsoft Windows environments. It has the following two major components: 1. An extensive collection of prewritten tools, called controls. These controls are accessible as icons within a graphical programming environment for creating customized windows components (e.g., menus, dialog boxes, text boxes, slide bars, etc.). 2. A complete set of program commands, derived from Microsofts implementation of the classical Basic programming language. The command set includes features that embrace contemporary programming practices. The overall approach to Visual Basic programming is twofold: 1. Create a user interface that is appropriate to the particular application at hand. 2. Add a group of Basic instructions to carry out the actions associated with each of the controls. Visual Basic is event-driven, meaning code remains idle until called upon to respond to some event (button pressing, menu selection etc). Visual Basic is governed by an event processor. Nothing happens until an event is detected. Once an event is detected, the code corresponding to that event (event procedure) is executed. Program control is then returned to the event processor.

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

Structure of a Visual Basic Application

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.

f) General Procedures - Code not related to objects. This code must be

invoked by the application. g) Modules - Collection of general procedures, variable declarations, and constant definitions used by application.

Steps in Developing a Visual Basic Application


There are three primary steps involved in building a Visual Basic application: 1. Draw the user interface 2. Assign properties to controls 3. Attach code to controls

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

d1.Text = b11 d2.Text = b21

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

Private Sub Command3_Click() End End Sub

Algorithm for 4 by 4 Matrix Inversion


10 Draw up a 4 by 4 matrix

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.

Highlights and Deficiencies of Method of solution


The method of solution employed in this program is the co-factor/adjoint method. The method as we all know is easy to understand but it is very long because of the step by step breakdown of the methodology employed. The highlights of this method of solution include; -

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.

Sample of the Input and Output of the Program


We are going to test run the program with a 4 by 4 matrix. The input is on the left side of the program interface while the output is on the right side of the program interface. A sample run of the program is displayed below;

Before output is calculated

After the output has been displayed

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

x1 = Val(p1x.Text) y1 = Val(p1y.Text) x2 = Val(p2x.Text) y2 = Val(p2y.Text)

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 = 0

ElseIf (dx = 0 And dy < 0) Then Bearing = (Atn(dx / dy)) * (180 / (4 * Atn(1))) TrueBearing = 180

ElseIf (dx > 0 And dy = 0) Then TrueBearing = 90

ElseIf (dx < 0 And dy = 0) Then TrueBearing = 270

End If

text6.Text = TrueBearing

latitude = dist * Cos(TrueBearing) Text1.Text = latitude

departure = dist * Sin(TrueBearing) Text2.Text = departure

End Sub

Private Sub Command2_Click() End End Sub

Private Sub Command3_Click() p1x.Text = "" p2x.Text = "" p1y.Text = "" p2y.Text = "" Distance.Text = "" text6.Text = "" Text1.Text = "" Text2.Text = "" End Sub

Algorithm for Backward Computation


10 20 30 Input coordinate of points A and B Let E = EB EA Let N = NB - NA

40 50

Let = Tan-1(E/N) Let {deg} = * (180/(atn(1)*4))

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

Highlights and Deficiencies of Method of Solution


The method of solution employed in this problem is very easy to use and easily understandable. As regards the program itself, there are a couple of deficiencies of which includes; - Inadequate text boxes to enable the program compute results for more coordinates. - Multi tasking is not enabled in the program.

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.

Sample of input and output of the program

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;

You might also like