# Gaussian seidel iteration technique

Page 1 of 1

## 1 Replies - 2554 Views - Last Post: 13 November 2012 - 12:12 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=299927&amp;s=512a03de0762dd120bc7913ebda33482&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 MEFerrara

Reputation: 0
• Posts: 1
• Joined: 12-November 12

# Gaussian seidel iteration technique

Posted 12 November 2012 - 10:09 PM

``` 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.

Is This A Good Question/Topic? 0

## Replies To: Gaussian seidel iteration technique

### #2 BobRodes

• Lovable Curmudgeon

Reputation: 590
• Posts: 3,041
• Joined: 19-May 09

## Re: Gaussian seidel iteration technique

Posted 13 November 2012 - 12:12 PM

Let's see if we can troubleshoot this first, before deciding your professor doesn't know his stuff and looking for a "better" way to do it. First, please explain in detail the procedure that you used to check your code. "I am not getting the right answers when I check them with a calculator" doesn't give us enough to go on.

This post has been edited by AdamSpeight2008: 13 November 2012 - 07:51 PM
Reason for edit:: Removal of Double Posting