Extreme Optimization – Curves (Function Mapping) Part 1
- by JoshReuben
Overview
· a curve is a functional map relationship between two factors (i.e. a function - However, the word function is a reserved word).
· You can use the EO API to create common types of functions, find zeroes and calculate derivatives - currently supports constants, lines, quadratic curves, polynomials and Chebyshev approximations.
· A function basis is a set of functions that can be combined to form a particular class of functions.
The Curve class
· the abstract base class from which all other curve classes are derived – it provides the following methods:
· ValueAt(Double) - evaluates the curve at a specific point.
· SlopeAt(Double) - evaluates the derivative
· Integral(Double, Double) - evaluates the definite integral over a specified interval.
· TangentAt(Double) - returns a Line curve that is the tangent to the curve at a specific point.
· FindRoots() - attempts to find all the roots or zeroes of the curve.
· A particular type of curve is defined by a Parameters property, of type ParameterCollection
The GeneralCurve class
· defines a curve whose value and, optionally, derivative and integrals, are calculated using arbitrary methods. A general curve has no parameters.
· Constructor params: RealFunction delegates – 1 for the function, and optionally another 2 for the derivative and integral
· If no derivative or integral function is supplied, they are calculated via the NumericalDifferentiation and AdaptiveIntegrator classes in the Extreme.Mathematics.Calculus namespace.
// the function is 1/(1+x^2)
private double f(double x)
{
return 1 / (1 + x*x);
}
// Its derivative is -2x/(1+x^2)^2
private double df(double x)
{
double y = 1 + x*x;
return -2*x* / (y*y);
}
// The integral of f is Arctan(x), which is available from the Math class.
var c1 = new GeneralCurve (new RealFunction(f), new RealFunction(df), new RealFunction(System.Math.Atan));
// Find the tangent to this curve at x=1 (the Line class is derived from Curve)
Line l1 = c1.TangentAt(1);