Skip to content

josnidhin/CubicSpline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Algorithm from Wiki

Input: set of coordinates C, with |C| = n+1

Output: set splines which is composed of n 5-tuples.

Create new array a of size n + 1 and for i = 0 ,..., n set ai = yi

Create new arrays b and d each of size n.

Create new array h of size n and for i = 0 ,..., n-1 set hi = xi+1 - xi

Create new array α of size n and for i = 1 ,..., n-1 set αi = (3 / h[i] x (ai+1 - ai)) - (3 / hi-1 x (ai - ai-1)).

Create new arrays c, l, μ, and z each of size n+1

Set l0 = 1, u0 = z0 = 0

For i = 1 ,..., n-1

  • Set li = 2 x( xi+1-xi-1) - hi-1 x ui-1.
  • Set ui = hi/li.
  • Set zi = (αi-1 - (hi-1 x zi-1)) / li
  • Set ln = 1; zn = cn = 0

For j = n-1 , n-2 ,..., 0

  • Set cj = zj - uj x cj+1
  • Set bj = ((aj+1 - aj) / hj) - (hj x (cj+1 + 2 x cj) / 3)
  • Set dj = (cj+1 - cj) / (3 x hj)

Create new set Splines and call it output_set. Populate it with n splines S.

For i = 0 ,..., n-1

  • Set Si,a = ai
  • Set Si,b = bi
  • Set Si,c = ci
  • Set Si,d = di
  • Set Si,x = xi

Output output_set

About

A simple cubic spline interpolation example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published