@@ -2068,46 +2068,33 @@ def derivativeFunction(self):
2068
2068
else :
2069
2069
return Function (lambda x : self .differentiate (x ))
2070
2070
2071
- def integralFunction (self , lower = None , upper = None , datapoints = 100 ):
2072
- """Returns a Function object representing the integral of the Function object.
2071
+ def integralFunction (self , lower = None ):
2072
+ """Returns a Function object representing the integral of the Function
2073
+ object.
2073
2074
2074
2075
Parameters
2075
2076
----------
2076
2077
lower : scalar, optional
2077
- The lower limit of the interval in which the function is to be
2078
- plotted. If the Function is given by a dataset, the default
2079
- value is the start of the dataset.
2080
- upper : scalar, optional
2081
- The upper limit of the interval in which the function is to be
2082
- plotted. If the Function is given by a dataset, the default
2083
- value is the end of the dataset.
2084
- datapoints : int, optional
2085
- The number of points in which the integral will be evaluated for
2086
- plotting it, which draws lines between each evaluated point.
2087
- The default value is 100.
2078
+ The lower integration limit. If the Function is given by a dataset
2079
+ of points the default value is the start of the dataset. If the
2080
+ Function is defined by a callable, then this parameter must be
2081
+ given.
2088
2082
2089
2083
Returns
2090
2084
-------
2091
2085
result : Function
2092
- The integral of the Function object.
2086
+ The integral function of the Function object. Note that the domain
2087
+ of the integral function is the same as the domain of the original
2088
+ Function object.
2093
2089
"""
2094
- # Check if lower and upper are given
2095
- if lower is None :
2096
- if isinstance (self .source , np .ndarray ):
2097
- lower = self .source [0 , 0 ]
2098
- else :
2099
- raise ValueError ("Lower limit must be given if source is a function." )
2100
- if upper is None :
2101
- if isinstance (self .source , np .ndarray ):
2102
- upper = self .source [- 1 , 0 ]
2103
- else :
2104
- raise ValueError ("Upper limit must be given if source is a function." )
2105
-
2106
- # Create a new Function object
2107
- xData = np .linspace (lower , upper , datapoints )
2108
- yData = np .zeros (datapoints )
2109
- for i in range (datapoints ):
2110
- yData [i ] = self .integral (lower , xData [i ])
2090
+ if callable (self .source ):
2091
+ return Function (lambda x : self .integral (lower , x ))
2092
+
2093
+ # Not callable, i.e., defined by a dataset of points
2094
+ lower = lower if lower is not None else self .source [0 , 0 ]
2095
+ xData = self .source [:, 0 ]
2096
+ yData = [self .integral (lower , x ) for x in xData ]
2097
+
2111
2098
return Function (
2112
2099
np .concatenate (([xData ], [yData ])).transpose (),
2113
2100
inputs = self .__inputs__ ,
0 commit comments