Wednesday, January 25, 2012

Simultaneous Equations Solver

How to design a program that can solve mixed simultaneous equations, that is , one linear equation and one quadratic equation. Here is the program:

Private Sub Command1_Click()
Dim a, b, c, d, m, n As Integer
Dim x1, x2, y1, y2 As Double
a = Val(Txt_a.Text)
b = Val(Txt_b.Text)
m = Val(Txt_m.Text)
c = Val(Txt_c.Text)
d = Val(Txt_d.Text)
n = Val(Txt_n.Text)
x1 = (m * a * d + Sqr(m ^ 2 * a ^ 2 * d ^ 2 - (b ^ 2 * c + a ^ 2 * d) * (d * m ^ 2 - b ^ 2 * n))) / (b ^ 2 * c + a ^ 2 * d)
x2 = (m * a * d - Sqr(m ^ 2 * a ^ 2 * d ^ 2 - (b ^ 2 * c + a ^ 2 * d) * (d * m ^ 2 - b ^ 2 * n))) / (b ^ 2 * c + a ^ 2 * d)
y1 = (m - a * x1) / b
y2 = (m - a * x2) / b
Lbl_x1.Caption = Round(x1, 2)
Lbl_y1.Caption = Round(y1, 2)
Lbl_x2.Caption = Round(x2, 2)
Lbl_y2.Caption = Round(y2, 2)
End Sub
===========================================================
 
Explanation:
Mixed simultaneous equations take the following forms:
ax+by=m
cx2+dy2=n
Simultaneous equations can normally be solved by the substitution or elimination methods. In this program, I employed the substitution method. So, I obtained the following formulae:
x1 = (m a d + Sqr(m 2 a 2 d 2 - (b 2 c + a 2 d) (d m 2 - b 2 n))) / (b 2 c + a 2 d)
x2 = (m a d +-Sqr(m 2 a 2 d 2 - (b 2 c + a 2 d) (d m 2 - b 2 n))) / (b 2 c + a 2 d)
y1 = (m - a x1) / b
y2 = (m - a x2) / b
To limit the answers to two decimal places, I used the round function.

Cubic Function Graph Plotter

This is a program that enables the user  to input the coefficients of a cubic function and draw its graph. The cubic function takes the form  f(x)=ax3+bx2+cx+d

The Code

Private Sub cmd_draw_Click()
Dim a, b, c, d As Integer
Dim w, v As Double
a = Val(txt_a.Text)
b = Val(txt_b.Text)
c = Val(txt_c.Text)
d = Val(txt_d.Text)
'Using a scale of 0.5 cm to represent i unit to draw the graph
' Need to make some transformation as the coordinates in VB start from top left

For w = 0 To 10 Step 0.001
v = a * (5 - w) ^ 3 + b * (5 - w) ^ 2 + c * (5 - w) + d
pic_graph.PSet (w, 5 - v)
Next w
End Sub

Wednesday, January 11, 2012

INTERNET BROWSER IN VB

Its very simple to make a web browser in vb.Just take four command buttons -GO,BACK,FORWARD & REFRESH.after this ,press ctrl+T. now select internet controls and then clickAPPLY.
Now u will find a small globe in ur toolbox.Double-click on it and a white box will appear .
Adjust it according ot ur form.

Now u r ready for the CODE-
Private Sub cmdgo_Click()
WebBrowser1.Navigate (Text1.Text)
End Sub
Private Sub cmdback_Click()
WebBrowser1.GoBack
End Sub
Private Sub Cmdforward_Click()
WebBrowser1.GoForward
End Sub
Private Sub cmdrefresh_Click()
WebBrowser1.Refresh
End Sub

Private Sub Form_Load()
WebBrowser1.Navigate ("http://www.google.com")
End Sub
Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
Text1.Text = (WebBrowser1.LocationURL)
Form1.Caption = (WebBrowser1.LocationName)
End Sub