Public Class Form1
Dim factor As Double
Dim x(2000) As Double, sum As Double
Dim Cells(8000, 8000) As Double
Dim k As Integer
Dim pc As Double = 0
Dim pw As Double = 0
Dim g As Double = 0
Dim w As Double = 0
Dim h1 As Double = 0
Dim h2 As Double = 0
Dim w1 As Double = 0
Dim w2 As Double = 0
Dim dx As Double
Dim a(8000, 8000) As Double, b(8000) As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MATRIX_A() ' h1=h2 rectangular shape or square
MATRIX_B() ' h1<>h2 irregular shape
SOLUTION() 'solution
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
TextBox8.Clear()
TextBox9.Clear()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox10.Clear()
End Sub
Private Sub MATRIX_A()
Dim i As Integer, j As Integer, n As Integer, i1 As Integer, j1 As Integer, n1 As Integer = 2
Dim h1 As Double = 0, h2 As Double
Try
'Check for Integers first
If Not Double.TryParse(TextBox1.Text, h1) Then
Throw New ApplicationException( _
"The first number must be an integer")
End If
If Not Double.TryParse(TextBox2.Text, h2) Then
Throw New ApplicationException( _
"The second number must be an integer")
End If
If Not Double.TryParse(TextBox3.Text, w1) Then
Throw New ApplicationException( _
"The second number must be an integer")
End If
If Not Double.TryParse(TextBox4.Text, w2) Then
Throw New ApplicationException( _
"The second number must be an integer")
End If
If Not Double.TryParse(TextBox5.Text, pc) Then
Throw New ApplicationException( _
"The second number must be an integer")
End If
If Not Double.TryParse(TextBox6.Text, pw) Then
Throw New ApplicationException( _
"The second number must be an integer")
End If
If Not Double.TryParse(TextBox7.Text, g) Then
Throw New ApplicationException( _
"The second number must be an integer")
End If
If Not Double.TryParse(TextBox8.Text, dx) Then
Throw New ApplicationException( _
"The second number must be an integer")
End If
n = h2 / dx * (w1 / dx - 1) + w2 / dx * (h1 / dx - h2 / dx - 1) + (w1 / dx - w2 / dx - 2) * 1 / 2 * (w1 / dx - w2 / dx - 1)
h1 = h2
If h1 = h2 Then
For i = w1 / dx To (w1 / dx - 1) * (h1 / dx - 2) + 1 Step w1 / dx - 1
For j = w1 / dx To n + 1 Step n
a(i, n + 1) = pw * g * (1 / 12) ^ 2 * (1 / 1000) * (h1 - n1 * dx)
n1 = n1 + 1
Next j
Next i
a(1, n + 1) = pc * g * h1 * (1 / 12) ^ 2 * (1 / 1000) + pw * g * (h1 - dx) * (1 / 12) ^ 2 * (1 / 1000)
For i = 2 To w1 / dx Step 1
For j = n + 1 To (w1 / dx - 2) * (n + 1) Step n + 1
a(i, n + 1) = pc * g * h1 * (1 / 12) ^ 2 * (1 / 1000)
Next
Next
i = j
For i = 1 To n
For j = 1 To n
If i = j Then
a(i, j) = -4
ElseIf i - 1 = j Then
a(i, j) = 1
For i1 = w1 / dx To (w1 / dx - 1) * (h1 / dx - 2) + 1 Step w1 / dx - 1
For j1 = w1 / dx - 1 To i1 - 1 Step w1 / dx - 1
a(i1, j1) = 0
Next
Next
ElseIf i + 1 = j Then
a(i, j) = 1
For i1 = w1 / dx - 1 To (w1 / dx - 1) * (h1 / dx - 2) Step w1 / dx - 1
For j1 = w1 / dx To i1 + 1 Step w1 / dx - 1
a(i1, j1) = 0
Next
Next
ElseIf i + w1 / dx - 1 = j And w1 = w2 Then
a(i, j) = 1
ElseIf w1 <> w2 And j = i + (w1 / dx - 1) Then
a(i, j) = 1
a((w1 / dx - 1) * h2 / dx, (w1 / dx - 1) * h2 / dx + w1 / dx - 1) = 0
If i > (w1 / dx - 1) * h2 / dx Then
a(i, j) = 0
End If
ElseIf i - (w1 / dx - 1) = j And w1 = w2 Then
a(i, j) = 1
ElseIf i - (w1 / dx - 1) = j And w1 <> w2 Then
a(i, j) = 1
a((w1 / dx - 1) * h2 / dx + w1 / dx - 1, (w1 / dx - 1) * h2 / dx) = 0
If i > (w1 / dx - 1) * h2 / dx + w1 / dx - 1 Then
a(i, j) = 0
End If
Else
a(i, j) = 0
End If
Next j
Next i
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error in Entry", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub MATRIX_B()
Dim i As Integer, j As Integer, n As Integer, i1 As Integer, j1 As Integer, i2 As Integer, i3 As Integer
Dim h3 As Integer, i4 As Integer, j4 As Integer, n1 As Integer = 2, i5 As Integer, j5 As Integer, i6 As Integer
Dim i1a As Integer, i2a As Integer, i7 As Integer, j7 As Integer, i8 As Integer, j8 As Integer
Dim i9 As Integer, j9 As Integer, i10 As Integer, j10 As Integer, i2b As Integer
Try
'Check for Integers first
If Not Double.TryParse(TextBox1.Text, h1) Then
Throw New ApplicationException( _
"The first number must be an integer")
End If
If Not Double.TryParse(TextBox2.Text, h2) Then
Throw New ApplicationException( _
"The second number must be an integer")
End If
If Not Double.TryParse(TextBox3.Text, w1) Then
Throw New ApplicationException( _
"The second number must be an integer")
End If
If Not Double.TryParse(TextBox4.Text, w2) Then
Throw New ApplicationException( _
"The second number must be an integer")
End If
If Not Double.TryParse(TextBox5.Text, pc) Then
Throw New ApplicationException( _
"The second number must be an integer")
End If
If Not Double.TryParse(TextBox6.Text, pw) Then
Throw New ApplicationException( _
"The second number must be an integer")
End If
If Not Double.TryParse(TextBox7.Text, g) Then
Throw New ApplicationException( _
"The second number must be an integer")
End If
If Not Double.TryParse(TextBox8.Text, dx) Then
Throw New ApplicationException( _
"The second number must be an integer")
End If
If h1 <> h2 Then
n = h2 / dx * (w1 / dx - 1) + w2 / dx * (h1 / dx - h2 / dx - 1) + (w1 / dx - w2 / dx - 2) * 1 / 2 * (w1 / dx - w2 / dx - 1)
a(1, n + 1) = pc * g * h1 * (1 / 12) ^ 2 * (1 / 1000) + pw * g * (h1 - dx) * (1 / 12) ^ 2 * (1 / 1000)
For i = 2 To w1 / dx Step 1
For j = n + 1 To (w1 / dx - 2) * (n + 1) Step n + 1
a(i, n + 1) = pc * g * h1 * (1 / 12) ^ 2 * (1 / 1000)
Next
Next
i = j
For i = 1 To n
For j = 1 To n
If i = j Then
a(i, j) = -4
ElseIf i = j + 1 And h3 < (w1 / dx - 1) * (h2 / dx) + w1 / dx - 1 Then
a(i, j) = 1
i3 = 1
Do While i3 < h1 / dx
i3 = i3 + 1
h3 = i3 * dx
Loop
For i1 = w1 / dx To (w1 / dx - 1) * h2 / dx + 1 Step w1 / dx - 1
For j1 = w1 / dx - 1 To (w1 / dx - 1) * h2 / dx Step w1 / dx - 1
a(i1, j1) = 0
Next
Next
For i5 = w1 / dx To (w1 / dx - 1) * (h2 / dx) + w1 / dx - 1 Step w1 / dx - 1
For j5 = w1 / dx To n + 1 Step n
a(i5, n + 1) = pw * g * (1 / 12) ^ 2 * (1 / 1000) * (h1 - n1 * dx)
n1 = n1 + 1
Next j5
Next i5
a(i, j) = 1
For i1 = w1 / dx - 1 To (w1 / dx - 1) * h2 / dx Step w1 / dx - 1
For j1 = w1 / dx To i1 + 1 Step w1 / dx - 1
a(i1, j1) = 0
Next
Next
'///////////////h3 >= (w1 / dx - 1) * (h2 / dx) + w1 / dx - 1////////
If i = j + 1 And h3 >= (w1 / dx - 1) * (h2 / dx) + w1 / dx - 1 Then
a(i, j) = 1
i1 = (w1 / dx - 1) * (h2 / dx) + w1 / dx - 1
j1 = (w1 / dx - 1) * (h2 / dx) + w1 / dx - 2
a(i1, j1) = 0
i2 = 2
Do While i2 <= (h1 - h2 - 2 * dx) / dx
i2 = i2 + 1
i1 = i1 + (w1 - i2 * dx) / dx
j1 = j1 + (w1 - i2 * dx) / dx
i4 = i1
j4 = j1
a(i4, j4) = 0
Loop
i1a = (w1 / dx - 1) * (h2 / dx) + w1 / dx - 1
a(i1a, n + 1) = pw * g * (1 / 12) ^ 2 * (1 / 1000) * (h1 - n1 * dx)
n1 = n1 + 1
i2a = 2
Do While i2a <= (h1 - h2 - 2 * dx) / dx
i2a = i2a + 1
i1a = i1a + (w1 - i2a * dx) / dx
i6 = i1a
a(i6, n + 1) = pw * g * (1 / 12) ^ 2 * (1 / 1000) * (h1 - n1 * dx)
n1 = n1 + 1
Loop
a(i, j) = 1
i1 = (w1 / dx - 1) * (h2 / dx) + w1 / dx - 2
j1 = (w1 / dx - 1) * (h2 / dx) + w1 / dx - 1
a(i1, j1) = 0
i2 = 2
Do While i2 <= (h1 - h2 - 2 * dx) / dx
i2 = i2 + 1
i1 = i1 + (w1 - i2 * dx) / dx
j1 = j1 + (w1 - i2 * dx) / dx
i7 = i1
j7 = j1
a(i7, j7) = 0
Loop
'///////////////////start here!!/////////////
i8 = (w1 / dx - 1) * h2 / dx + 1
j8 = i8 + (w1 - 2 * dx) / dx
a(i8, j8) = 1
i2 = 1
Do While i2 < (h1 - h2 - 2 * dx) / dx
i2 = i2 + 1
i8 = i8 + (w1 - i2 * dx) / dx
j8 = j8 + (w1 - i2 * dx) / dx - 1
i9 = i8
j9 = j8
a(i9, j9) = 1
Loop
End If
'///////////////////end here!!/////////////
End If
Next j
Next i
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error in Entry", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub SOLUTION()
Dim i As Integer, j As Integer, n As Integer
TextBox9.Text = h2 / dx * (w1 / dx - 1) + w2 / dx * (h1 / dx - h2 / dx - 1) + (w1 / dx - w2 / dx - 2) * 1 / 2 * (w1 / dx - w2 / dx - 1)
n = TextBox9.Text
n = h2 / dx * (w1 / dx - 1) + w2 / dx * (h1 / dx - h2 / dx - 1) + (w1 / dx - w2 / dx - 2) * 1 / 2 * (w1 / dx - w2 / dx - 1)
i = j
For i = 1 To n Step 1
For j = 1 To n + 1 Step 1
TextBox10.AppendText(a(i, j) & vbTab)
Application.DoEvents()
Next j
b(i) = a(i, n + 1)
Next i
End Sub
End Class