|
From: d p. <mr....@gm...> - 2005-02-23 10:54:36
|
!DhbNumericalMethodsTestCase methodsFor: 'functionEvaluation' ! testSplineDifferentiation " self debug: #testSplineDifferentiation " | interval testInterval interpolator | interval := 0.0 to: 10.0 by: 0.1. testInterval := 1.0 to: 9.0 by: 0.05. interpolator := DhbSplineInterpolator new. interval do: [:x | interpolator add: x @ x sin]. testInterval do: [:x | self assert: (x cos - (interpolator valueDerivative: x)) abs < 1.0e-6]! ! !DhbSplineInterpolator methodsFor: 'information' ! valueDerivative: aNumber "needs a trivial refactoring with #value to remove identical code" | answer n1 n2 n step a b constantTerm aTerm bTerm | coefficients isNil ifTrue: [self computeSecondDerivatives]. n2 := pointCollection size. n1 := 1. [n2 - n1 > 1] whileTrue: [n := (n1 + n2) // 2. (self xPointAt: n) > aNumber ifTrue: [n2 := n] ifFalse: [n1 := n]]. step := (self xPointAt: n2) - (self xPointAt: n1). a := ((self xPointAt: n2) - aNumber) / step. b := (aNumber - (self xPointAt: n1)) / step. constantTerm := ((self yPointAt: n2) - (self yPointAt: n1)) / step. aTerm := (coefficients at: n1) * (1 - (3 * a squared)) * step / 6 . bTerm := (coefficients at: n2) * (1 - (3 * b squared)) * step / 6 . ^ constantTerm + aTerm - bTerm. ! ! |