anchor.diff:              D.[i-1,i]   <- h.[i]/6.0
               D.[i,i-1] <- h.[i]/6.0
   
  -
  -        //generation of matrices P, U and B (Wood) --- Matrix P corrected!
  +        //generation of matrices P, U and B (Wood94) --- Matrix P corrected!
           let P = Array2D.zeroCreate n n
           let U = Array2D.zeroCreate n n
   
  
positive.code:                             Matrix.setRow Ctemp (4*i-1) (- (temp - (B.Row (i) |> vector)))
                              if i = j - 1 then
                                  Matrix.setRow Ctemp (4*i-4) (Vector.zero Ctemp.NumCols)
                                  Matrix.setRow Ctemp (4*i-3) -(B.Row (i-1) |> vector) //0??
                                  Matrix.setRow Ctemp (4*i-2) (Vector.zero Ctemp.NumCols)
                                  Matrix.setRow Ctemp (4*i-1) (Vector.zero Ctemp.NumCols)
                          for i = j to n-1 do
  
negative.code:     open FSharp.Stats
      open FSharp.Stats.Optimization
  
      let initEvalAt (x:Vector<float>) (a:Vector<float>) (c:Vector<float>) =
  
          let n = x.Length
  
          //define interval stepwidths
          let h = Vector.init (n-1) (fun i -> x.[i+1] - x.[i] )
          // helper functions f(i,1-4)(t) for smoothing spline
          let calcF1 (h:Vector<float>) (x:Vector<float>) (i:int) (t:float) =
              (x.[i+1] - t) / h.[i]
  
          let calcF2 (h:Vector<float>) (x:Vector<float>) (i:int) (t:float) =
              (t - x.[i]) / h.[i]
  
          let calcF3 (h:Vector<float>) (x:Vector<float>) (i:int) (t:float) =
              ((calcF1 h x i t)**3.0 - (calcF1 h x i t) ) * (h.[i]**2.0) / 6.0
  
          let calcF4 (h:Vector<float>) (x:Vector<float>) (i:int) (t:float) =
              ((calcF2 h x i t)**3.0 - (calcF2 h x i t) ) * (h.[i]**2.0) / 6.0
  
          // helper function s(i) for smoothing spline 
          let calcS (h:Vector<float>) (x:Vector<float>) (a:Vector<float>) (c:Vector<float>) (i:int) (t:float) =
              a.[i] * (calcF1 h x i t) + a.[i+1] * (calcF2 h x i t) + c.[i] * (calcF3 h x i t) + c.[i+1] * (calcF4 h x i t)
  
          let evalAt =  calcS h x a c 
      
          (fun t ->
              let i = 
                  match Array.tryFindIndexBack (fun xs -> xs <= t) (x.InternalValues) with 
                  | Some x -> x 
                  | None   -> failwith "The x-value is not part of the section used to estimate the spline coefficients, thus a monotone function progression can not be guaranteed"
              evalAt i t
              )
  
      //calculates extrema with (type,x_value) where type is +1 for maxima and -1 for minima
      let getExtrema (x:Vector<float>) (a:Vector<float>) (c:Vector<float>) =
          let n = x.Length
          //define interval stepwidths
          let h = Vector.init (n-1) (fun i -> x.[i+1] - x.[i] )
  
          let searchExtrema i (a:Vector<float>) (c:Vector<float>) =
              //checks, if a polynomial coefficient vanishes 
              let isZero (coeff: float) =
                  let tolerance = 0.00001
                  if (Math.Abs coeff) <= tolerance then 0. else coeff
              let (lower,upper) = 0.,1.
              let aCoeff = -1./6. * c.[0] + 1./6. * c.[1]                 |> isZero
              let bCoeff = 0.5 * c.[0]                                    |> isZero
              let cCoeff = -1./3. * c.[0] - 1./6. * c.[1] - a.[0] + a.[1] |> isZero
  
              let aCoeff' = 3. * aCoeff
              let bCoeff' = 2. * bCoeff
              let cCoeff' = cCoeff
  
              let aCoeff'' = 2. * aCoeff'
              let bCoeff'' = bCoeff'
  
              let findFstDeriv_Zero =
                  let root = (pown bCoeff' 2) - 4. * aCoeff' * cCoeff'
                  if root < 0. then [] 
                  else 
                      let result1 = (- bCoeff' + sqrt(root)) / (2. * aCoeff')
                      let result2 = (- bCoeff' - sqrt(root)) / (2. * aCoeff')
                      if result1 = result2 then
                          [result1]
                      else [result1;result2]
  
              let slope0 =    
                  //check wether the extremum is inside the interval [0,1] (hermite basis interval)
                  findFstDeriv_Zero |> List.filter (fun x -> x >= lower && x <= upper)
  
              slope0
              |> List.map (fun xValNorm -> 
                  //recalculate the true xValue outside the normed interval [0,1]
                  let xVal = h.[i] * xValNorm + x.[i]
                  let getSndDerivative =
                      aCoeff'' * xValNorm + bCoeff''
                  match getSndDerivative with
                  | getSndDerivative when getSndDerivative = 0. -> (0.,0.)
                  | getSndDerivative when getSndDerivative < 0. -> (1.,xVal)
                  | _                                           -> (-1.,xVal)
                  )
              |> List.filter (fun v -> v <> (0.,0.))
  
          x.[ .. x.Length-2]
          |> Array.ofSeq
          |> Array.map (fun intervalStart -> 
              let i =
                  if intervalStart = Seq.last x then 
                      Seq.length x - 2
                  else
                      x
                      |> Seq.findIndex(fun x_Knot -> (x_Knot - intervalStart) > 0.)
                      |> fun nextInterval -> nextInterval - 1
              searchExtrema i a.[i .. i + 1] c.[i .. i + 1]
              )
          |> Array.filter (fun x -> x <> [])
          |> List.concat
          |> List.distinctBy (fun (indicator,xVal) -> round 2 xVal )
  
      type Condition =
          | In0 //monotonically increasing
          | In1 //1 maximum
          | In2 //2 maxima
          | De0 //monotonically decreasing
          | De1 //1 minimum
          | De2 //2 minima
          | Complex //more complex
  
  
      //check the spline for the predefined condition
      let checkshape (x:Vector<float>) (a:Vector<float>) (c:Vector<float>) (con:Condition)=
          let extrema = getExtrema x a c
          let extremaCount = extrema.Length
          let n = a.Length
          match con with
          | In0       -> extremaCount = 0 && a.[0] <= a.[n-1]
          | In1       -> extremaCount = 1 && (fst extrema.[0]) = 1.
          | In2       -> extremaCount = 2 && (fst extrema.[0]) = 1. && (fst extrema.[1]) = -1.
          | De0       -> extremaCount = 0 && a.[0] >= a.[n-1]
          | De1       -> extremaCount = 1 && (fst extrema.[0]) = -1.
          | De2       -> extremaCount = 2 && (fst extrema.[0]) = -1. && (fst extrema.[1]) = 1.
          | Complex   -> true
  
      let mapCondition (operator:Matrix<float> -> matrix) con =
          let mat = matrix [[1.]]
          match con with
          | x when con = 0 -> if mat = operator mat then Condition.De0 else Condition.In0
          | x when con = 1 -> if mat = operator mat then Condition.De1 else Condition.In1
          | x when con = 2 -> if mat = operator mat then Condition.De2 else Condition.In2
  
      type TempClassResult = {
          //spline function values at knots
          TraceA   : vector
          //spline second derivative values at knots
          TraceC   : vector
          //weighted error of a and y
          Error    : float
          //mGCV
          GCV      : float
          //used smoothing factor lambda
          Lambda   : float
          //used constraint matrix for shape determination
          Ctemp    : float [,]
          //AIC determined by SSE and the number of used extrema
          AICc     : float
          //function, that returns the splines' value at a given x_value
          SplineFunction  : (float -> float)}
      
      let createTempClassResult a c e gcv lambda ctemp aic splinefunction = {
          TraceA          = a
          TraceC          = c
          Error           = e
          GCV             = gcv
          Lambda          = lambda
          Ctemp           = ctemp
          AICc            = aic
          SplineFunction  = splinefunction
          } 
      
      let private unzip4 li =
          let length = Seq.length li
  