Simultaneous Equations Solver

 

It has been sometimes we have not deal with mathematical problems, so why not focus on this subject once again. Actually the thought of programming a mathematical tool came across my mind when my son asked me some questions associated with simultaneous equations. Then It dawned on me that why not I program a simultaneous equation solver so that it can solve my son's problems as well as my problems too. There you are, the program is ready and I am showing the codes here:

Private Sub Command1_Click()
Dim a, b, c, d, m, n As Integer
Dim x, y 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)
x = (b * n - d * m) / (b * c - a * d)
y = (a * n - c * m) / (a * d - b * c)
Lbl_x.Caption = Round(x, 2)
Lbl_y.Caption = Round(y, 2)

End Sub

Private Sub Command2_Click()
Txt_a.Text = ""
Txt_b.Text = ""
Txt_m.Text = ""
Txt_c.Text = ""
Txt_d.Text = ""
Txt_n.Text = ""
Lbl_x.Caption = ""
Lbl_y.Caption = ""

End Sub

 


Explanation:

Linear simultaneous equations take the following forms:

 

ax+by=m

cx+dy=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:

 

x = (b * n - d * m) / (b * c - a * d)
y = (a * n - c * m) / (a * d - b * c)

 

To limit the answers to two decimal places, I used the round function.

 

 

 

 

 

 

 [Back to VBToday]