Ok, so this is a 2-D flat plate heat conduction finite difference code...or at least it will be when its finished. Right now everything runs great until the last do loop where you basically find an interior value by averaging the 4 values around it. For some reason this is coming up with average values that are much bigger than any of the 4 values being averaged. The error it gives me when almost through the first run of the outter do loop is "type missmatch". The only think can think of is that the U(2,4) is essentially blowing up to infinity since the trend is for the output of this loop to increase very very rapidly. If I take the U(x, y - 1) term out of this loop and replace it with a constand it works just fine. This value is of course the output from the previous loop which has blown up considerably. Here's the code, I underlined the equation at the bottom that is causing all the fuss.

```
Sub Maincode()
'---------------------------Main Code Module-----------------------------------
'dim the integers
Dim N As Integer
Dim Nnodes As Integer 'number of nodes in each direction
Dim Nelem As Integer 'number of elements in each direction
Dim Ntot As Integer 'number of array elements with midpoints
Dim x As Integer
Dim y As Integer
'dim the reals
Dim H As Double 'element length
Dim Ldist As Double 'Length of flat plate
Dim Hdist As Double 'Heigth of flat plate
Dim Pi As Double
'dim the arrays
Dim U() As String 'Temperature at point (i,j)
Dim UP() As String 'First derrivative of temp
'Dim UPP() As String 'second derrivative of temp
Dim Xdist() As String 'x position (length) of each node
Dim Ydist() As String 'y position (height) of each node
Dim Eh() As String 'Error at each node and midpoint
Dim EhP() As String 'First derrivative of error
Dim AU() As String 'Analytical temp at point (i,j)
Dim AUP() As String 'First derrivative of analytical temp
N = 2
Ldist = 1
Hdist = 1
Pi = 3.14159
If MainForm.Nval.Value = True Then
N = MainForm.Nval.Value
End If
If MainForm.Lval.Value = True Then
Ldist = MainForm.Lval.Value
End If
If MainForm.Hval.Value = True Then
Hdist = MainForm.Hval.Value
End If
H = 1 / 2 ^ N
Nelem = Ldist * 2 ^ N
Nnodes = Nelem + 1
Ntot = Nelem + Nnodes
'allocate the arrays
ReDim U(Nnodes, Nnodes) As String
ReDim UP(Nelem, Nelem) As String
ReDim Xdist(Nnodes) As String
ReDim Ydist(Nnodes) As String
ReDim Eh(Nelem, Nelem) As String
ReDim EhP(Nelem, Nelem) As String
ReDim AU(Nnodes, Nnodes) As String
ReDim AUP(Nnodes, Nnodes) As String
'set up x and y distance arrays
Xdist(1) = 0#
Ydist(1) = 0#
x = 2
Do Until x = Nnodes + 1
Xdist(x) = Xdist(x - 1) + H
x = x + 1
Loop
x = 2
Do Until x = Nnodes + 1
Ydist(x) = Ydist(x - 1) + H
x = x + 1
Loop
'Initial guess of temperature
x = 1
Do Until x = Nnodes + 1
y = 1
Do Until y = Nnodes + 1
U(x, y) = 50#
y = y + 1
Loop
x = x + 1
Loop
' ---------------Set up the Temperature matrix for the flat plate----------------
'Surfaces where temperature is zero (DC and AB)
x = 1
Do Until x = Nnodes + 1
U(1, x) = 0#
U(Nnodes, x) = 0#
x = x + 1
Loop
' Along AD
x = 2
Do Until x = Nnodes
U(x, 1) = (2# * H * Sin(Pi * Ydist(x)) + 2 * U(x, 2) + U(x + 1, 1) + U(x - 1, 1)) / 4#
x = x + 1
Loop
'Along BC
x = 2
Do Until x = Nnodes
U(x, Nnodes) = (2# * U(x, Nnodes - 1) + U(x + 1, Nnodes) + U(x - 1, Nnodes)) / 4#
x = x + 1
Loop
'In between dreams...
x = 2
Do Until x = Nnodes
y = 2
Do Until y = Nnodes
[U]U(x, y) = (U(x, y + 1) + U(x, y - 1) + U(x - 1, y) + U(x + 1, y)) / 4#[/U]
y = y + 1
Loop
x = x + 1
Loop
End Sub
```

Display More
Any help you can offer is much appreciated...

Thanks and Gig 'em

-Rick