Taking your data in account from link you provided:
data={{......}};
Find the model:
model = Fit[data, x^# & /@ Range[0, 10], x]
20.2513 + 43.3389 x - 0.208411 x^2 + 0.193888 x^3 - 0.0341689 x^4 +
0.00281455 x^5 - 0.000131003 x^6 + 3.64629*10^-6 x^7 -
6.01724*10^-8 x^8 + 5.43205*10^-10 x^9 - 2.06702*10^-12 x^10
Verify it is more or less correct:
Show[ListPlot[data, PlotStyle -> Directive[PointSize[.02], Opacity[.02], Red]],
Plot[model, {x, -7, 55}, PlotStyle -> Thickness[.005]],
Frame -> True, Axes -> False, ImageSize -> 500]
The blue line inside is your model. Red line is your data points blended together (too many of them) with applied opacity. I've chosen so many polynomial terms to take in account well little bent at the beginning. You can play with number of polynomial terms.
Export your model to C:
CForm[model]
20.251253486790134 + 43.33892854755122*x - 0.20841104603541305*Power(x,2) +
0.19388822209706186*Power(x,3) - 0.03416888859439315*Power(x,4) +
0.0028145533596680857*Power(x,5) - 0.0001310033312242676*Power(x,6) +
3.646291289683582e-6*Power(x,7) - 6.017238075935027e-8*Power(x,8) +
5.432049184033492e-10*Power(x,9) - 2.0670190082996488e-12*Power(x,10)
y
values? $\endgroup$BSplineCurve
: reference.wolfram.com/mathematica/ref/… $\endgroup$BSplineCurve
documentation page rather than the one forBSplineBasis
. To get the goodness-of-fit statistics you can probably useBSplineBasis
withLinearModelFit
rather than constructing the design matrix manually as shown in the example. I'd have posted an answer except I wasn't sure if that was what you were looking for and haven't used splines for anything before, so I have no real familiarity with them. Please feel free to self-answer if you like. $\endgroup$