プログラムリスト
VBAのプログラムリストは以下のようになります。
Dim Xi(1001), Yi(1001), B(1001)
Sub Main()
Sheets("Sheet2").Select
Cells.Select
Selection.Clear
'初期入力
x0 = Sheets("Sheet1").Cells(3, 2).Value
dx = Sheets("Sheet1").Cells(4, 2).Value
N = Sheets("Sheet1").Cells(5, 2).Value
Ni = Sheets("Sheet1").Cells(8, 2).Value
For i = 1 To Ni Step 1
Xi(i) = Sheets("Sheet1").Cells(9 + i, 2).Value
Yi(i) = Sheets("Sheet1").Cells(9 + i, 3).Value
Next i
'タイトル
Sheets("Sheet2").Cells(1, 1).Formula = "No"
Sheets("Sheet2").Cells(1, 2).Formula = "x"
Sheets("Sheet2").Cells(1, 3).Formula = "補間y"
'表作成
For k = 0 To N Step 1
Y = 0
X = x0 + dx * k
For i = 1 To Ni Step 1
B(i) = 1
For j = 1 To Ni Step 1
If j = i Then
Else
B(i) = B(i) * (X - Xi(j)) / (Xi(i) - Xi(j))
End If
Next j
Y = Y + B(i) * Yi(i)
Next i
Sheets("Sheet2").Cells(2 + k, 1).Value = k
Sheets("Sheet2").Cells(2 + k, 2).Value = X
Sheets("Sheet2").Cells(2 + k, 3).Value = Y
Next k
End Sub