内维尔的算法

时间:2016-03-18 08:53:30

标签: arrays algorithm vba for-loop

我对Neville的算法有疑问,问题是数组不能与 for 一起使用。

这是我的代码:

Sub Neville()
    Cells.Clear
    grado = InputBox("Give me the degree of the polynomial")
    x = InputBox("give me the searched x ")
    ReDim vectorx(0 To grado)
    ReDim fx(0 To grado)
        For i = 1 To grado
            vectorx(i) = InputBox("Dame x" & i - 1, "Valores en x")
            fx(i) = InputBox("Dame y" & i - 1 & "ó f(x)" & i - 1, "Valores en y")
            Cells(i + 1, 1) = vectorx(i)
            Cells(i + 1, 2) = fx(i)
            For d = 1 To grado - 2
                Cells(i + 1, d + 2) = (((x - (vectorx(i - 1))) * (fx(i))) - (x - (vectorx(i))) * (fx(i - 1))) / (vectorx(i) - vectorx(i - 1))
                Cells(i + 1, d + 4) = Cells(i + 1, d + 2)
                Cells(i + 1, d + 4) = Cells(i + 1, d + 2)
                Cells(6, 8) = vectorx(i - 1)
            Next
        Next
End Sub

0 个答案:

没有答案