anchor.diff:      module Interpolation =
           
           type BoundaryCondition =
  +            ///most used spline variant: f'' at borders is set to 0
               | Natural
  +            ///f' at first point is the same as f' at the last point
               | Periodic
  +            ///f'' at first/second and last/penultimate knot are equal
               | Parabolic
  +            ///f''' at second and penultimate knot are continuous
               | NotAKnot
  +            ///first and last polynomial are quadratic, not cubic
               | Quadratic
  +            ///f' at first and last knot are set by user
               | Clamped
                 
           ///computes all coefficients for piecewise interpolating splines. In the form of [a0;b0;c0;d0;a1;b1;...;d(n-2)]. 
  -        ///fn(x) = (an)x+(bn)x+(cn)x+(dn)
  +        ///where: fn(x) = (an)x+(bn)x+(cn)x+(dn)
           let coefficients (boundaryCondition: BoundaryCondition) (x_Values: Vector<float>) (y_Values: Vector<float>) =
               //f(x)   = ax+bx+cx+d
               //f'(x)  = 3ax+2bx+c
               //f''(x) = 6ax+2b
   
  -            let intervalNumber = x_Values.Length - 1
  +            let (xVal,yVal) =
  +                let indices =
  +                    x_Values
  +                    |> Seq.indexed
  +                    |> Seq.sortBy snd
  +                    |> Seq.map fst
  +                let sortedX_Values = indices |> Seq.map (fun i -> x_Values.[i]) |> vector
  +                let sortedY_Values = indices |> Seq.map (fun i -> y_Values.[i]) |> vector
  +                sortedX_Values,sortedY_Values
  +
  +            let intervalNumber = xVal.Length - 1
   
               let interpolatingConstraints intervalIndex (x:float) (y:float) =
                   let tmp = Array.init (4 * intervalNumber) (fun x -> 0.)
  
negative.code:                     [|0 .. intervalNumber - 1|]
                      |> Array.map (fun i -> 
                          [|
                          interpolatingConstraints i xVal.[i] yVal.[i]
                          interpolatingConstraints i xVal.[i+1] yVal.[i+1]
                          |])
                          |> Array.concat
  
  