I'm glad that fixed it! I'm certainly not a maths pro, but I do use maths applications in my work as an engineer.
But if you want to replicate the behaviour of the Excel curve fitting function you don't want the curvefit routines (which fit a best approximation smooth curve through scattered data) but rather the curvebuild routines, which fit a smoothcurve exactly through each specified point. The closest match to the Excel function is probably the CatmullRom curve, with a low "tension" value (0 or 0.1 I think). VBA code for that is
Code:
Function CRSpline1DA(XA As Variant, YA As Variant, XIA As Variant, Optional EndType As Long = 0, Optional Tension As Double = 0) As Variant
Dim CMResA() As Double, NumXRows As Long, NumXIrows As Long, i As Long, J As Long
Dim XAD() As Double, YAD() As Double, Rtn As Variant, Tbl() As Double
Dim C1 As Spline1DInterpolant
Rtn = GetSplineData(XA, YA, XAD, YAD, NumXRows, XIA, NumXIrows)
If Rtn <> 0 Then
CRSpline1DA = Rtn
Exit Function
End If
Spline1DBuildCatmullRom XAD, YAD, NumXRows, EndType, Tension, C1
ReDim CMResA(1 To NumXIrows, 1 To 1)
For i = 1 To NumXIrows
CMResA(i, 1) = Spline1DCalc(C1, XIA(i, 1))
Next i
CRSpline1DA = CMResA
End Function
If you want the parameters of the curve, rather than the Y values for specific X values use:
Spline1DUnpack C1, NumXRows, Tbl
instead of Spline1DCalc(C1, XIA(i, 1))
Note that the curves are made up of a series of cubic curves (a + bx +cx^2 + dx^3), rather than one higher order polynomial curve. Look in the AlgLib manual and code for more details.
You also might find the following posts from my blog helpful (and I hope not too mathematical):
http://newtonexcelbach.wordpress.com/20 ... c-splines/http://newtonexcelbach.wordpress.com/20 ... l-splines/Also follow up the comments from Lori Miller on my blog, which are talking about replicating the Excel smooth curves.