Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Maintaing Extrapolation when Adding Discrete Functions with Constants #432

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions rocketpy/mathutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -1716,8 +1716,9 @@ def __add__(self, other):
outputs = self.__outputs__[0] + " + " + other.__outputs__[0]
outputs = "(" + outputs + ")"
interpolation = self.__interpolation__
extrapolation = self.__extrapolation__
# Create new Function object
return Function(source, inputs, outputs, interpolation)
return Function(source, inputs, outputs, interpolation, extrapolation)
else:
return Function(lambda x: (self.get_value(x) + other(x)))
# If other is Float except...
Expand All @@ -1734,8 +1735,11 @@ def __add__(self, other):
outputs = self.__outputs__[0] + " + " + str(other)
outputs = "(" + outputs + ")"
interpolation = self.__interpolation__
extrapolation = self.__extrapolation__
# Create new Function object
return Function(source, inputs, outputs, interpolation)
return Function(
source, inputs, outputs, interpolation, extrapolation
)
else:
return Function(lambda x: (self.get_value(x) + other))
# Or if it is just a callable
Expand Down Expand Up @@ -1842,8 +1846,9 @@ def __mul__(self, other):
outputs = self.__outputs__[0] + "*" + other.__outputs__[0]
outputs = "(" + outputs + ")"
interpolation = self.__interpolation__
extrapolation = self.__extrapolation__
# Create new Function object
return Function(source, inputs, outputs, interpolation)
return Function(source, inputs, outputs, interpolation, extrapolation)
else:
return Function(lambda x: (self.get_value(x) * other(x)))
# If other is Float except...
Expand All @@ -1860,8 +1865,11 @@ def __mul__(self, other):
outputs = self.__outputs__[0] + "*" + str(other)
outputs = "(" + outputs + ")"
interpolation = self.__interpolation__
extrapolation = self.__extrapolation__
# Create new Function object
return Function(source, inputs, outputs, interpolation)
return Function(
source, inputs, outputs, interpolation, extrapolation
)
else:
return Function(lambda x: (self.get_value(x) * other))
# Or if it is just a callable
Expand Down Expand Up @@ -1927,8 +1935,9 @@ def __truediv__(self, other):
outputs = self.__outputs__[0] + "/" + other.__outputs__[0]
outputs = "(" + outputs + ")"
interpolation = self.__interpolation__
extrapolation = self.__extrapolation__
# Create new Function object
return Function(source, inputs, outputs, interpolation)
return Function(source, inputs, outputs, interpolation, extrapolation)
else:
return Function(lambda x: (self.get_value_opt(x) / other(x)))
# If other is Float except...
Expand All @@ -1945,8 +1954,11 @@ def __truediv__(self, other):
outputs = self.__outputs__[0] + "/" + str(other)
outputs = "(" + outputs + ")"
interpolation = self.__interpolation__
extrapolation = self.__extrapolation__
# Create new Function object
return Function(source, inputs, outputs, interpolation)
return Function(
source, inputs, outputs, interpolation, extrapolation
)
else:
return Function(lambda x: (self.get_value_opt(x) / other))
# Or if it is just a callable
Expand Down Expand Up @@ -1980,8 +1992,9 @@ def __rtruediv__(self, other):
outputs = str(other) + "/" + self.__outputs__[0]
outputs = "(" + outputs + ")"
interpolation = self.__interpolation__
extrapolation = self.__extrapolation__
# Create new Function object
return Function(source, inputs, outputs, interpolation)
return Function(source, inputs, outputs, interpolation, extrapolation)
else:
return Function(lambda x: (other / self.get_value_opt(x)))
# Or if it is just a callable
Expand Down Expand Up @@ -2029,8 +2042,9 @@ def __pow__(self, other):
outputs = self.__outputs__[0] + "**" + other.__outputs__[0]
outputs = "(" + outputs + ")"
interpolation = self.__interpolation__
extrapolation = self.__extrapolation__
# Create new Function object
return Function(source, inputs, outputs, interpolation)
return Function(source, inputs, outputs, interpolation, extrapolation)
else:
return Function(lambda x: (self.get_value_opt(x) ** other(x)))
# If other is Float except...
Expand All @@ -2047,8 +2061,11 @@ def __pow__(self, other):
outputs = self.__outputs__[0] + "**" + str(other)
outputs = "(" + outputs + ")"
interpolation = self.__interpolation__
extrapolation = self.__extrapolation__
# Create new Function object
return Function(source, inputs, outputs, interpolation)
return Function(
source, inputs, outputs, interpolation, extrapolation
)
else:
return Function(lambda x: (self.get_value(x) ** other))
# Or if it is just a callable
Expand Down Expand Up @@ -2082,8 +2099,9 @@ def __rpow__(self, other):
outputs = str(other) + "**" + self.__outputs__[0]
outputs = "(" + outputs + ")"
interpolation = self.__interpolation__
extrapolation = self.__extrapolation__
# Create new Function object
return Function(source, inputs, outputs, interpolation)
return Function(source, inputs, outputs, interpolation, extrapolation)
else:
return Function(lambda x: (other ** self.get_value(x)))
# Or if it is just a callable
Expand Down Expand Up @@ -2323,7 +2341,9 @@ def derivative_function(self):
outputs = f"d({self.__outputs__[0]})/d({inputs[0]})"

# Create new Function object
return Function(source, inputs, outputs, self.__interpolation__)
return Function(
source, inputs, outputs, self.__interpolation__, self.__extrapolation__
)

def integral_function(self, lower=None, upper=None, datapoints=100):
"""Returns a Function object representing the integral of the Function
Expand Down Expand Up @@ -2491,6 +2511,7 @@ def inverse_function(self, approx_func=None, tol=1e-4):
inputs=self.__outputs__,
outputs=self.__inputs__,
interpolation=self.__interpolation__,
extrapolation=self.__extrapolation__,
)

def find_input(self, val, start, tol=1e-4):
Expand Down