Click or drag to resize

PiecewiseLinearFunction Class

Represents a piecewise linear function for calculating values between pivot points.
Inheritance Hierarchy
SystemObject
  GSF.NumericalAnalysis.InterpolationPiecewiseLinearFunction

Namespace: GSF.NumericalAnalysis.Interpolation
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.181-beta
Syntax
public class PiecewiseLinearFunction
View Source

The PiecewiseLinearFunction type exposes the following members.

Constructors
 NameDescription
Public methodPiecewiseLinearFunctionInitializes a new instance of the PiecewiseLinearFunction class
Top
Properties
 NameDescription
Public propertyDomain Gets the x-values of the pivot points in the piecewise linear function.
Public propertyRange Gets the y-values of the pivot points in the piecewise linear function.
Top
Methods
 NameDescription
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Public methodSetDomain Sets the x-values of the pivot points in the piecewise linear function.
Public methodSetRange Sets the y-values of the pivot points in the piecewise linear function.
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Operators
 NameDescription
Public operatorStatic member(PiecewiseLinearFunction to FuncDouble, Double) Converts the PiecewiseLinearFunction object to a FuncT, TResult to start converting values.
Top
Extension Methods
 NameDescription
Public Extension MethodGetEnumValueOrDefault Gets the enumeration constant for value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Public Extension MethodGetEnumValueOrDefaultT Gets the enumeration constant for this value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Top
Remarks

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.

C#
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
See Also