Extreme Optimization > User's Guide > Mathematics Library > Curves > Curve Basics

Extreme Optimization User's Guide

User's Guide

Up: Curves Next: Simple Curves Previous: Curves Contents

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 Line curve 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 zeroes 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 of type ParameterCollection . The number of such parameters is given by the Count property of this collection. The ToArray method of the Parameters collection returns a array with the values of the parameters.

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 RealFunction delegates.

A general curve has no parameters.

To create a general curve, call the constructor with one, two, or three RealFunction delegates as parameters. The first parameter 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 the NumericalDifferentiator class in the Extreme.Mathematics.Calculus namespace.

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 Ai. It calculates the tangent line to each curve at x = 1 using the , and finds the point at which they intersect.

C# CopyCode imageCopy Code
// 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 (new RealFunction(f),
        new RealFunction(df), new RealFunction(System.Math.Atan));
    // Find the tangent to this curve at x=1
    Line 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 Airy class
    // of the Extreme.Mathematics.SpecialFunctions namespace.
    GeneralCurve c2 = new GeneralCurve (
        new RealFunction(Extreme.Mathematics.SpecialFunctions.Airy.Ai),
        new RealFunction(Extreme.Mathematics.SpecialFunctions.Airy.AiPrime));
    // Find the tangent to this curve at x=1
    Line l2 = c2.TangentAt(1);
    // Just for fun, let's find out where these two tangent lines intersect:
    Point p = Point.FromIntersection(l1, l2);
    Console.WriteLine("The lines meet at ({0},{1})", p.X, p.Y);
}
Visual Basic CopyCode imageCopy Code
' Our function is 1/(1+x^2)
Private Function f(x As Double) As Double
    Return 1 / (1 + x*x)
End Function
' Its derivative is -2x/(1+x^2)^2
' The derivative of 1/(1+x^2) is ArcTan(x)
Private Function df(x As Double) As Double
    Dim y As Double = 1 + x*x
    Return -2*x* / (y*y)
End Function

' Now let's use these:
Public Sub TestGeneralCurve()
    ' The integral of f is Arctan(x), which is available from the Math class.
    Dim c1 As GeneralCurve = New GeneralCurve (new RealFunction(f), _
        new RealFunction(AddressOf df), _
        new RealFunction(AddressOf System.Math.Atan))
    ' Find the tangent to this curve at x=1
    Line 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 Airy class
    ' of the Extreme.Mathematics.SpecialFunctions namespace.
    Dim c2 As GeneralCurve = _
        New GeneralCurve (New RealFunction(AddressOf SpecialFunctions.Airy.Ai), _
        New RealFunction(AddressOf SpecialFunctions.Airy.AiPrime))
    ' Find the tangent to this curve at x=1
    Line l2 = c2.TangentAt(1)
    ' Just for fun, let's find out where these two tangent lines intersect:
    Dim p As Point = Point.FromIntersection(l1, l2)
    Console.WriteLine("The lines meet at ({0},{1})", p.X, p.Y)
End Sub

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.

Up: Curves Next: Simple Curves Previous: Curves Contents

Overview
Introduction
Features
Documentation
QuickStart Samples
Sample Applications
Downloads
Get it now!
Download trial version
How to Buy
Information
Resources
Contact Us
Search

"The Extreme Optimization Statistics Library for .NET is a major boon for those doing statistical work in .NET. I strongly recommend this product."
- Marc Brooks

"I have made it my mission to institutionalize the value of good API design.  I strongly believe that this is key to making developers more productive and happy on our platform. It is clear that you value good API design in your work, and take to heart developer productivity and synergy with the .NET framework."
- Brad Abrams,
Lead Program Manager, Microsoft.

This is a partial list of companies who are using our libraries:
ABB Robotics
Allstate
Applied Materials
Arcam
Astra Schedule
Babson College
Canadian Council on Learning
Canyon Associates
Caxton Associates
CECity
Constellation Energy
CreditSights
DeepOcean
Duke University
Dynamotive
Elecsoft
Engelhard Corporation
Epcor
Equipoise Software
Galileo International
GAM UK
Gammex
GlaxoSmithKline
Global Matrix
The Hartford
Infinera Corporation
Intel
JDS Uniphase
LaBranche & Co.
Learning & Skills Council
Jacobs Consultancy
Litman Gregory
Lucas Systems
Malvern Instruments
Medrio
Merck & Co.
Mintera.
Monitor Software
MorningStar
NanoString Technologies
Paletta Invent
Parametric Portfolio Associates
Prosanos
RATA Associates
RiskShield
Ramboll
Standard & Poor's
Strategic Analysis Corporation
Univ. of Alicante
Univ. of South Carolina
vielife
Xerox
US Army