Friday, April 30, 2010

Cable analysis with central point load

The following is a cable analysis with central point load using VBA excel code created by the author to produce approximate numerical solutions:

Private Sub CALC_Click()
Dim e, Lp, i, T As Double
i = Sheets(1).Cells(7, 2).Value
e = Sheets(1).Cells(8, 2).Value
T = Sheets(1).Cells(9, 2).Value
Lp = Sheets(1).Cells(16, 3).Value
For n = Lp To T Step i
Sheets(1).Cells(16, 3).Value = n
If Sheets(1).Cells(16, 9).Value < e Then GoTo 100
Next n
100:
End
End Sub


Saturday, April 3, 2010

ITERATION & NEWTON-RAPHSON METHOD

The following is an iteration using VBA excel code created by the author to produce approximate numerical solutions to certain mathematical problems:

Private Sub Commanditerate_Click()

Range("A8:c8").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents

Dim a, b, e, per As Double
e = Sheets(2).Cells(3, 2).Value
For x = 1 To 1000000

a = Sheets(2).Cells(6, 2).Value
b = Sheets(2).Cells(6, 3).Value
per = Abs((a - b) / b) * 100
If per < e Then GoTo 100

Sheets(2).Cells(6, 1).Value = x
Sheets(2).Cells(6, 2).Value = b
Sheets(2).Cells(7 + x, 1).Value = x
Sheets(2).Cells(7 + x, 2).Value = b
Next x

100:
Sheets(2).Cells(2, 2).Value = b
Sheets(2).Cells(7 + x, 1).Value = x
Sheets(2).Cells(7 + x, 2).Value = b
Range("b6:b6").Select
End Sub

Below is a video of iteration method by using Newton-Raphson Method


GAUSS ELIMINATION

In linear algebra, Gaussian elimination is an algorithm for solving systems of linear equations, finding the rank of a matrix, and calculating the inverse of an invertible square matrix The following is a sample of VBA excel code created by the author: Private Sub Clear_Click() Application.ScreenUpdating = False Dim ans As String ans = MsgBox("Data will be cleared. Please confirm ", vbYesNo + vbExclamation) If ans = vbNo Then End Sheets(8).Activate 'clear content of matrix Sheets(8).Range("A10:IV1000").Select Selection.ClearContents Sheets(8).Cells(3, 2).Select End Sub Private Sub Compute_Click() Dim N, div, multi As Integer 'reading data N = Sheets(8).Cells(3, 2).Value ReDim c(N, N + 1) For i = 1 To N For j = 1 To N + 1 c(i, j) = Sheets(8).Cells(i + 10, j + 3).Value Next j Next i 'ensure c(1, 1) <> 0 If c(1, 1) = 0 Then Call msg0 Else 'forward elimination of pivot row For i = 1 To N div = c(i, i) For j = i To N + 1 c(i, j) = c(i, j) / div Next j For k = i + 1 To N multi = c(k, i) For j = i To N + 1 c(k, j) = c(k, j) - multi * c(i, j) Next j Next k Next i 'back substitution For i = N To 0 Step -1 For k = N To i + 1 Step -1 c(i, N + 1) = c(i, N + 1) - c(i, k) * c(k, N + 1) Next k Next i 'value of unknown For i = 1 To N Sheets(8).Cells(i + 10, 1) = c(i, N + 1) Next i End Sub Sub msg250() MsgBox ("n value is limit to 250 only!") End End Sub Sub msg0() MsgBox ("C(1,1) is equal to 0") End End Sub Private Sub GenerateGE_Click() Dim N As Integer Dim ans As String Application.ScreenUpdating = False Sheets(8).Activate 'N as number of row or column N = Sheets(8).Cells(3, 2).Value 'limit N to 250 If N > 250 Then Call msg250 Else For i = 1 To N Sheets(8).Cells(i + 10, 3) = i Sheets(8).Cells(10, i + 3) = i Next i Sheets(8).Cells(10, N + 4) = N + 1 Sheets(8).Cells(11, 2).Select End Sub