3

I read the article on https://www.value-at-risk.net/cubic-spline-interpolation/

I understand all but I don't know how I can get the values for the matrix:

enter image description here

I know that there is something like hi = hi+1 - hi

I visited several websites, read different explenations, but I never found out how exactly I come to this values in the matrix.

zer0kai
  • 239
  • 1
  • 4
  • 12
  • I assume you want to know how they goes from [2.127] to [2.128], which mean: how to solve `M.X = V` , with M a square Matrix of dimension `n`, X and V are vectors of dimension `n` ? – yaitloutou Jan 29 '17 at 11:11
  • I want to know how they get the values for the matrix M. – zer0kai Jan 29 '17 at 11:12
  • 1
    then, you need to edit your question, and include more details, btw, I think, this question is more suited for http://math.stackexchange.com – yaitloutou Jan 29 '17 at 11:14
  • I mentioned twice in my question, that I need to know how exactly I get the values for the matrix. Where is the problem? – zer0kai Jan 29 '17 at 11:16
  • 1
    there is no problem :) I'am trying to understand what you're looking for to give you a better answer. and because your question is unrelated to programming it's [off-topic](http://stackoverflow.com/help/on-topic) here. so, I suggested an other place, where you can find more answers. – yaitloutou Jan 29 '17 at 11:41
  • @YounesAitLoutou I agree ... btw this has nothing to do with SPLINEs euther it is just simple cubic polynomial fit – Spektre Jan 29 '17 at 12:51
  • @Spektre indeed, I just can't write all the mathematics symbol quickly to explain [Representing linear systems with matrix equations](https://www.khanacademy.org/math/precalculus/precalc-matrices/solving-equations-with-inverse-matrices/v/matrix-equations-systems). and I think this what the OP is looking for. considering that he "understand all but ..." – yaitloutou Jan 29 '17 at 13:02
  • @zer0kai added few things to answer (you accepted quicker then I finish editing :) ) – Spektre Jan 29 '17 at 13:21

1 Answers1

4

The matrix is just system of equations encoded as matrix so it can be easily computed by inverse matrix.

For example second line of matrix (8,4,2,1,0,0,0,0) after matrix multiplication means this:

a3.2^3+a2.1^2+a1.2^1+a0=5

which is your p1(2)=5 the lines are:

p1(1)=1
p1(2)=5
p2(2)=5
p2(3)=4
p1'(2)-p2'(2)=0
p1''(2)-p2''(2)=0
p1''(1)=0
p2''(3)=0

so for example last matrix line ( 0,0,0,0,18,2,0,0 ) is this:

b3.18 + b2.2 = 0

If we derive p2(t) up to 2-nd derivation

p2(t) = b3.t^3 + b2.t^2 + b1.t + b0
p2'(t) = 3.b3.t^2 + 2.b2.t + b1
p2''(t) = 2.3.b3.t + 1.2.b2  = 6.b3.t + 2.b2

Now for t=3 we get:

p2''(3) = 6.b3.3 + 2.b2 = 18.b3 + 2.b2

And encoded into matrix (last line)

(0,0,0,0,18,2,0,0) * ( a3,a2,a1,a0,b3,b2,b1,b0) = 0

Which matches your example. Hope it is clear now ...

Beware this example of yours is just for y axis as you got 2D curve you need to do this for x axis in the same manner again ...

Now let rewrite the matrix equation again:

M*A=B

Where M is your 8x8 matrix, A=(a3,a2,a1,a0,b3,b2,b1,b0) and B=(1,5,5,4,0,0,0,0) you can solve this like this:

inverse(M)*M*A = inverse(M)*B
             A = inverse(M)*B

So you obtain the A which holds your p1,p2 polynomials coefficients for B which holds your position (y coordinates in one pass and x coordinates in the next) so you got p1x,p1y,p2x,p2y polynomials. Which is what you need for the interpolation.

However this approach is a bit backward and usually predefined polynomial forms are used like SPLINE,BEZIER with defined properties like continuity, linearity, etc (no need for inverse matrix operation). But if you need custom properties like in this example then you do not have much of a choice.

For more info see How can i produce multi point linear interpolation?

Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380