1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| Sub NRmethod(N, eps, maxval)
Dim iter As Integer
Tw0 = Cells(23, 5)
Tg0 = Cells(23, 4)
Tf0 = Cells(23, 6)
qs0 = Cells(23, 2)
i = 24
Do While N > 0
Application.StatusBar = "N= " & N
If Abs(determinant(qs0, Tw0, Tg0, Tf0)) < eps Then
MsgBox "Error"
Exit Do
End If
Tw = Tw0 - jacobianinvmat(0, 0) * fw(qs0, Tw0, Tg0, Tf0) - jacobianinvmat(0, 1) * fg(qs0, Tw0, Tg0, Tf0) - jacobianinvmat(0, 2) * ff(Tw0, Tg0, Tf0)
Tg = Tg0 - jacobianinvmat(1, 0) * fw(qs0, Tw0, Tg0, Tf0) - jacobianinvmat(1, 1) * fg(qs0, Tw0, Tg0, Tf0) - jacobianinvmat(1, 2) * ff(Tw0, Tg0, Tf0)
Tf = Tf0 - jacobianinvmat(2, 0) * fw(qs0, Tw0, Tg0, Tf0) - jacobianinvmat(2, 1) * fg(qs0, Tw0, Tg0, Tf0) - jacobianinvmat(2, 2) * ff(Tw0, Tg0, Tf0)
Cells(i, 5) = Tw
Cells(i, 4) = Tg
Cells(i, 6) = Tf
If Abs(fw(qs, Tw, Tg, Tf)) < eps And Abs(fg(qs, Tw, Tg, Tf)) < eps And Abs(ff(Tw, Tg, Tf)) < eps Then
iter = 100 - N
Cells(i + 1, 6) = Tw
Cells(i + 1, 7) = Tg
Cells(i + 1, 8) = Tf
MsgBox "Convergence after " & iter & " iterations"
Exit Do
End If
If Abs(fw(qs, Tw, Tg, Tf)) > maxval And Abs(fg(qs, Tw, Tg, Tf)) > maxval And Abs(ff(Tw, Tg, Tf)) > maxval Then
iter = 100 - N
MsgBox "Divergence after " & iter & " iterations"
Exit Do
End If
N = N - 1
i = i + 1
Tw0 = Tw
Tg0 = Tg
Tf0 = Tf
Loop
MsgBox "No convergence after " & N & " iterations"
End Sub |
Partager