Curve Basics

The Curve Class

The Curve class is the abstract base class from which all other curve classes are derived. It defines a common set of methods and properties for curves.

The ValueAt method evaluates the curve at a specific point. SlopeAt evaluates the derivative, and Integral evaluates the definite integral over a specified interval. The TangentAt method returns a Polynomial of degree 1 that is the tangent to the curve at a specific point. If overridden by a descendant class, the GetDerivative method returns the curve that is the derivative of the instance. The FindRoots method attempts to find all the roots or zeros of the curve.

A particular type of curve is defined by a set of parameters. These parameters can be set and retrieved through the Parameters property, which is, which is a vector.

The Point Structure

A Point structure represents a point in two-dimensional space. It has two properties, X and Y that specify the x and y-coordinate of the point.

General Curves

A GeneralCurve is a curve whose value and, optionally, derivative and integrals, are calculated using user-supplied methods. The methods are supplied as Func<T, TResult> delegates.

A general curve has no parameters.

To create a general curve, call the constructor with one, two, or three Func<T, TResult> delegates as parameters. The first argument is the delegate used to evaluate the function. The second parameter, if present, specifies the derivative function. The third parameter, if present, specifies an integral function.

The ValueAt method simply evaluates the value delegate of the general curve.

If a derivative delegate has been supplied, it is used to by the SlopeAt, TangentAt, and GetDerivative methods. If no derivative was supplied, a numerical derivative is calculated using static methods in the FunctionMath class.

If an integral delegate has been supplied, it is used to by the Integral method. If no integral was supplied, a numerical integral is calculated using the AdaptiveIntegrator class in the Extreme.Mathematics.Calculus namespace.

The following example creates GeneralCurve objects, one for the function f(x) = 1/(1+x*x), and one for the Airy function AiryAi. It calculates the tangent line to each curve at x = 1 and finds the point at which they intersect.

// Our function is 1/(1+x^2)
private double f(double x)
    return 1 / (1 + x * x);
// Its derivative is -2x/(1+x^2)^2
// The derivative of 1/(1+x^2) is ArcTan(x)
private double df(double x)
    double y = 1 + x * x;
    return -2 * x / (y * y);
// Now let's use these:
public void TestGeneralCurve()
    // The integral of f is Arctan(x), which is available from the Math class.
    GeneralCurve c1 = new GeneralCurve(f, df, System.Math.Atan);
    // Find the tangent to this curve at x=1
    var l1 = c1.TangentAt(1);
    // Let's define a GeneralCurve for the Airy function Ai(x):
    // The Airy function and its derivative can be found 
    // in the class Extreme.Mathematics.Special, which defines
    // special functions.
    GeneralCurve c2 = new GeneralCurve(Special.AiryAi, Special.AiryAiPrime);
    // Find the tangent to this curve at x=1
    var l2 = c2.TangentAt(1);

For the first function, there is a closed form solution for the integral and the derivative. The integral for the Airy function isn't available. Note that we didn't really need to provide the integral here.