Sub pickup()
Dim A(), b(), x()
c1 = ActiveCell.Column
r1 = ActiveCell.Row
nr = Selection.Rows.Count
nc = Selection.Columns.Count
ReDim A(nr, nc), b(nc), x(nr)
e = 0.000001
For i = 1 To nr
r = r1 + i – 1
For j = 1 To nc
c = c1 + j - 1
A(i, j) = Cells(r, c).Value
Next j
b(i) = Cells(r, c1 + nc).Value
Next i
Call GS(A, b, x, e, numiter)
For i = 1 To nr
r = r1 + i + nr + 3
For j = 1 To nc
c = c1 + j + -1
Cells(r, c).Value = A(i, j)
Next j
Cells(r, c + 1).Value = b(i)
Cells(r, c + 3).Value = x(i)
Next i
Cells(r + 1, c + 3).Value = numiter
End Sub
Sub GS(A, b, x, e, m)
Dim sp As Double
nr = Selection.Rows.Count
nc = Selection.Columns.Count
For m = 1 To 1000
For i = 1 To nc
sp = 0
For j = 1 To nr
If i <> j Then sp = sp + A(i, j) * x(i)
Next j
xlast = x(i)
x(i) = (b(i) - sp) / A(i, i)
If Abs(x(i) - xlast) < e Then rc = rc + 1
Next i
If rc = nc Then Exit Sub
Next m
End Sub
I am not getting the right answers when i check them with a calculator. This is the method my professor gave us in class so if anyone knows a better route I am more than open to new methods. This is in VBA btw. If anyone can help i would appreciate it.

New Topic/Question
Reply



MultiQuote



|