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# | Copy 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 | Copy 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
Copyright 2004-2008,
Extreme Optimization. All rights reserved.
Extreme Optimization, Complexity made simple, M#, and M
Sharp are trademarks of ExoAnalytics Inc.
Microsoft, Visual C#, Visual Basic, Visual Studio, Visual
Studio.NET, and the Visual Studio Logo are registered trademarks of Microsoft Corporation