Skip to content

Commit

Permalink
FIX: fix left over bug in spline integral when bounds are out of domain
Browse files Browse the repository at this point in the history
  • Loading branch information
giovaniceotto committed Apr 2, 2023
1 parent 2024ab5 commit e5eefae
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions rocketpy/Function.py
Original file line number Diff line number Diff line change
Expand Up @@ -2225,10 +2225,17 @@ def integral(self, a, b, numerical=False):
# Check to see if interval starts before point data
if a < xData[0]:
if self.__extrapolation__ == "constant":
ans += yData[0] * (xData[0] - a)
ans += yData[0] * (min(xData[0], b) - a)
elif self.__extrapolation__ == "natural":
c = coeffs[:, 0]
subB = a - xData[0] # subA = 0
subB = a - xData[0]
subA = min(b, xData[0]) - xData[0]
ans += (
(c[3] * subA**4) / 4
+ (c[2] * subA**3 / 3)
+ (c[1] * subA**2 / 2)
+ c[0] * subA
)
ans -= (
(c[3] * subB**4) / 4
+ (c[2] * subB**3 / 3)
Expand Down Expand Up @@ -2271,10 +2278,10 @@ def integral(self, a, b, numerical=False):
# Check to see if interval ends after point data
if b > xData[-1]:
if self.__extrapolation__ == "constant":
ans += yData[-1] * (b - xData[-1])
ans += yData[-1] * (b - max(xData[-1], a))
elif self.__extrapolation__ == "natural":
c = coeffs[:, -1]
subA = xData[-1] - xData[-2]
subA = max(xData[-1], a) - xData[-2]
subB = b - xData[-2]
ans -= (
(c[3] * subA**4) / 4
Expand Down

0 comments on commit e5eefae

Please sign in to comment.