高斯塞德尔在VBA

时间:2017-11-12 20:11:17

标签: vba matrix

尝试使用Gauss seidel方法求解25乘25矩阵来解决2D传热化学工程问题。

但它没有进入第二次迭代

Do While error > 0.1

temps0 = temps1(UBound(matrix1, 1), 1) ' Old temperature for error calculation

'Conducts the gauss algorithm for each row
For i = 1 To UBound(matrix1, 1)
    temps1(i, 1) = matrix1(i, UBound(matrix1, 2))
    For j = 1 To (UBound(matrix1, 2) - 1)
        If j <> i Then
            temps1(i, 1) = temps1(i, 1) - (matrix1(i, j) * temps1(j, 1))
        ElseIf j = i Then
            divider = matrix1(i, j)
        End If
    Next j
    temps1(i, 1) = temps1(i, 1) / divider
Next i

error = Abs((temps1(UBound(matrix1, 1), 1) - temps0) / temps1(UBound(matrix1,     1), 1))
iteration = iteration + 1

Loop

这是高斯赛德尔的do while循环 Matrix1是由先前函数生成的coeff矩阵

真的很感激任何帮助。 TY

1 个答案:

答案 0 :(得分:0)

通过改变错误的值来解决问题,无论如何,谢谢

相关问题