xin chao cac bac. toi la thanh vien moi. Vua moi ghe qua, thay cac bac ban ve BVA hay qua ma toi thi chi moi biet. Con nhieu van de qua. Toi tham khao ham noi suy bac ba ma ko sao chay noi. Nho cac bac xem giup va ta cung ban bac nhe:
Option Explicit
Option Base 1 'Make arrays start at 1
'
'Ham noi suy bac 3
'
Function NoiSuyBacBa( rngXArray As Variant,
rngYArray As Variant, rngX As Variant ) As Double
Dim intIndex As Integer
Dim intI As Integer
Dim intJ As Integer
Dim dblProd As Double
'Find the location of the value to be interpolated.
For intIndex = 1 To UBound(rngXArray.Value)
If (rngX.Value < rngXArray.Value(intIndex)) Then
Exit For
End If
Next intIndex
'If it is less than 2 data points from either end of the table,
'reset the index to two points from the end.
If intIndex < 2 then intIndex = 2
If intIndex > UBound(rngXArray.Value) - 2 Then
intIndex = UBound(rngXArray.Value) - 2
End If
'Zero the summation variable.
NoiSuyBacBa = 0
' these loops calculate the terms in the Lagrangian form of the interpolation formula.
For intI = intIndex - 1 To intIndex + 2
If (intI <> intJ ) Then
dblProd = dblProd * (rngX.Value - rngXArray.Value(intJ))
/ (rngXArray.Value(intI) - rngXArray.Value(intJ))
End If
Next intJ
NoiSuyBacBa =NoiSuyBacBa + dblProd* rngYArray.Value(intI)
Next intI
End Function
'
'Use this procedure to run NoiSuyBacBa
'within the Module to test it.
'
Sub testit( )
Dim scratch As Double
scrach = NoiSuyBacBa("a1 ", "a1", "a1" )
End Sub
Co gi xin dc thinh giao cac bac nhe!