Piecewise
|
The PiecewiseLinearFunction type exposes the following members.
Name | Description | |
---|---|---|
PiecewiseLinearFunction | Initializes a new instance of the PiecewiseLinearFunction class |
Name | Description | |
---|---|---|
Domain | Gets the x-values of the pivot points in the piecewise linear function. | |
Range | Gets the y-values of the pivot points in the piecewise linear function. |
Name | Description | |
---|---|---|
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) | |
GetHashCode | Serves as the default hash function. (Inherited from Object) | |
GetType | Gets the Type of the current instance. (Inherited from Object) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) | |
SetDomain | Sets the x-values of the pivot points in the piecewise linear function. | |
SetRange | Sets the y-values of the pivot points in the piecewise linear function. | |
ToString | Returns a string that represents the current object. (Inherited from Object) |
Name | Description | |
---|---|---|
(PiecewiseLinearFunction to FuncDouble, Double) | Converts the PiecewiseLinearFunction object to a FuncT, TResult to start converting values. |
Name | Description | |
---|---|---|
GetEnumValueOrDefault |
Gets the enumeration constant for value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions) | |
GetEnumValueOrDefaultT |
Gets the enumeration constant for this value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions) |
The conversion function returned by this class uses a binary search algorithm to find the appropriate line segment to use for the calculation. Therefore, the domain must be specified either in increasing or decreasing order.
Here is an example of how to use this class.
Func<double, double> piecewiseLinearFunc = new PiecewiseLinearFunction() .SetDomain(-1, 0, 1) .SetRange(0, 1, 0); Console.WriteLine(piecewiseLinearFunc(-10)); // -9 Console.WriteLine(piecewiseLinearFunc(-1)); // 0 Console.WriteLine(piecewiseLinearFunc(-0.5)); // 0.5 Console.WriteLine(piecewiseLinearFunc(0)); // 1 Console.WriteLine(piecewiseLinearFunc(0.5)); // 0.5 Console.WriteLine(piecewiseLinearFunc(1)); // 0 Console.WriteLine(piecewiseLinearFunc(10)); // -9