I am trying to write on paper the piecewise polynomials given by the splinefit function, but I am having some problems figuring out what the coefficients should be. So, the output from the script gives me the following:

  scalar structure containing the fields:

form = pp
breaks =

 Columns 1 through 15:

  -1.00000  -0.93750  -0.87500  -0.81250  -0.75000  -0.68750  -0.62500  -0.56250  -0.50000   0.00000   0.50000   0.56250   0.62500   0.68750   0.75000

 Columns 16 through 19:

   0.81250   0.87500   0.93750   1.00000

coefs =

   2.5644e+03  -3.1686e+02   7.4332e+00  -1.0744e-01
  -2.5013e+02   1.6397e+02  -2.1226e+00  -2.5453e-01
  -2.4859e+03   1.1707e+02   1.5442e+01   1.9225e-01
   2.4278e+03  -3.4904e+02   9.4429e-01   1.0078e+00
   2.0742e+01   1.0618e+02  -1.4235e+01   2.9610e-01
  -9.0213e+02   1.1007e+02  -7.1939e-01  -1.7374e-01
   3.6900e+02  -5.9083e+01   2.4670e+00  -9.0075e-03
  -5.4428e+01   1.0105e+01  -5.9408e-01   4.4780e-03
   9.4209e-02  -1.0004e-01   3.1240e-02  -6.4667e-03
  -5.9852e-02   4.1271e-02   1.8542e-03  -4.0812e-03
  -5.3315e+01  -4.8507e-02  -1.7641e-03  -3.1792e-04
   3.5957e+02  -1.0045e+01  -6.3261e-01  -1.3634e-02
  -8.6341e+02   5.7374e+01   2.3254e+00  -4.6254e-03
  -4.0925e+01  -1.0452e+02  -6.2096e-01   1.5404e-01
   2.4543e+03  -1.1219e+02  -1.4165e+01  -3.0303e-01
  -2.4445e+03   3.4799e+02   5.7280e-01  -1.0274e+00
  -2.7185e+02  -1.1035e+02   1.5426e+01  -2.2903e-01
   2.2566e+03  -1.6132e+02  -1.5531e+00   2.3768e-01

pieces =  18
order =  4
dim =  1

If I plot the function via ppval, I get what I expect. But, if I take the first line of the coeff matrix, as I interpret it, I can write the me the first cubic polynomial as:

$f(x) = 2.5644 \times 10^3 x^3 -3.1686\times10^2 x^2 + 7.4332 x - 1.0744\times10^{-1}, \ -1 < x < -0.9375$

Just as a reference, $f(x=-1)\approx 0$ in the data I have, but clearly from the equation just shown that's not the case.

  • 1
    $\begingroup$ I found the answer. The spline is written as. $\sum_{n=0}^3 a_n(x-x_{inf})^n$ not as I previously mentioned $\endgroup$ – Kbzon Mar 20 '19 at 11:55
  • $\begingroup$ Was your question how to interpret the results provided by that specific function of MATLAB/Octave? $\endgroup$ – nicoguaro Mar 20 '19 at 15:25
  • 2
    $\begingroup$ @Kbzon: Are you able to answer your own question? It's helpful for closing out open questions. $\endgroup$ – Richard Mar 20 '19 at 17:42

I found the answer! Octave/MATLAB's function splinefit differs from polyfit in the sense that the polynomial in the former is proposed as:

$\sum_{n=0}^k a_n(x-x_o)^n$

and in the latter

$\sum_{n=0}^k a_n x^n$

Where $x_0$ refers to the range $[x_0,x_f]$ of the absissa.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.