Extreme Optimization >
User's Guide >
Mathematics Library >
Curves >
Simple Curves
Extreme Optimization User's Guide
User's Guide
Up: Curves Next: Polynomials Previous: Curve Basics Contents
Simple Curves
Simple curves here are those that are the simplest in form. The three curves in this section are: constants,
lines, and quadratic curves.
Constant Curves
The Constant class represents a curve with a constant
Y-value. It inherits from Curve and provides specialized
implementation for most methods.
A constant curve has one parameter: the Y-value.
To construct a Constant curve, simply pass the constant value to the constructor. There is one predefined Constant
curve, which is zero everywhere.
| C# | Copy Code |
Constant constant1 = new Constant(3);
Constant constant2 = Constant.Zero; |
| Visual Basic | Copy Code |
Dim constant1 As Constant = New Constant(3)
Dim constant2 As Constant = Constant.Zero |
The ValueAt method returns the
constant value of the curve. SlopeAt always returns
zero. Integral evaluates the definite integral over
a specified interval.
The GetDerivative method returns a
Constant with value zero.
A Constant curve is returned by the GetDerivative method of the Line class.
Lines
A Line curve describes a linear relationship between two
quantities. It has constant slope. Unless the slope is zero, it has one root. It inherits from Polynomial and provides specialized implementation for most
methods.
A line can be defined in many ways. The Line constructor is overloaded to reflect this. The first
option is to provide two points the line passes through. We can use the Point structure for this
purpose. Alternatively, we can pass the x and y co-ordinates of the tow points directly to the constructor:
| C# | Copy Code |
// Using Point structures:
Point point1 = new Point(1, 3);
Point point2 = new Point(4, 9);
Line line1 = new Line(point1, point2);
// Using coordinates directly:
Line line2 = new Line(point1.X, point1.Y, point2.X, point2.Y); |
| Visual Basic | Copy Code |
' Using Point structures:
Dim point1 As Point = New Point(1, 3)
Dim point2 As Point = New Point(4, 9)
Dim line1 As Line = New Line(point1, point2)
' Using coordinates directly:
Dim line2 As Line = New Line(point1.X, point1.Y, point2.X, point2.Y) |
A line is also completely defined when we provide one point the line passes through as well as the slope of the
line. We can use the Point structure, or we can pass the x and y-coordinates of the point.
| C# | Copy Code |
Line line3 = new Line(point1, 2);
Line line4 = new Line(point1.X, point1.Y, 2); |
| Visual Basic | Copy Code |
Dim line3 As Line = New Line(point1, 2)
Dim line4 As Line = New Line(point1.X, point1.Y, 2) |
Finally, we can construct a line using its slope and its value at x = 0:
| C# | Copy Code |
Line line5 = new Line(2, 1); |
| Visual Basic | Copy Code |
Dim line5 As Line = New Line(2, 1) |
A Line curve has two parameters: the Y-value where it crosses the Y-axis, and the slope of the
line.
The ValueAt method returns the value of the line at a
specific point. SlopeAt returns the constant slope of the
Line. Integral evaluates the definite
integral over a specified interval.
A line has one root, unless the slope is equal to zero, in which case there are either zero or infinitely many
roots. In the regular case, you can obtain the x value where the line intersects the y-axis as shown
below:
| C# | Copy Code |
Line line1 = new Line(1, 1, 2);
double root = line1.FindRoots()[0]; |
| Visual Basic | Copy Code |
Dim line1 As Line = New Line(1, 1, 2)
Dim root As Double = line1.FindRoots()[0] |
A Line curve is returned by the GetDerivative method of the Quadratic class.
Quadratic Curves
A Quadratic curve is a polynomial of degree 2. It can
have 0, 1 or 2 real roots. The Quadratic class inherits from Polynomial and provides specialized implementation for most
methods.
A quadratic curve can be defined in many ways. The Quadratic constructor is overloaded to reflect
this. The first option is to provide three points that lie on the curve. We can use the Point structure
for this purpose:
| C# | Copy Code |
Point point1 = new Point(-1, -4);
Point point2 = new Point(3, 12);
Point point3 = new Point(0, -3);
Quadratic quadratic1 = new Quadratic(point1, point2, point3); |
| Visual Basic | Copy Code |
Dim point1 As Point = New Point(-1, -4)
Dim point2 As Point = New Point(3, 12)
Dim point3 As Point = New Point(0, -3)
Dim quadratic1 As Quadratic = New Quadratic(point1, point2, point3) |
Alternatively, we can pass the x and y co-ordinates of the three points directly to the constructor:
| C# | Copy Code |
Quadratic quadratic2 = new Quadratic(point1.X, point1.Y,
point2.X, point2.Y, point3.X, point3.Y); |
| Visual Basic | Copy Code |
Dim quadratic2 As Quadratic = New Quadratic(point1.X, point1.Y, _
point2.X, point2.Y, point3.X, point3.Y) |
We can also give the coefficients of the quadratic, linear and constant terms:
| C# | Copy Code |
Quadratic quadratic3 = new Quadratic(1, 2, 1); |
| Visual Basic | Copy Code |
Dim quadratic3 As Quadratic = New Quadratic(1, 2, 1) |
A quadratic curve has three parameters: the coefficients of the quadratic, linear and constant terms.
The ValueAt method returns the value of the line at a
specific point. SlopeAt returns the slope of the
Quadratic. Integral evaluates the
definite integral over a specified interval. The GetDerivative method returns a Line object.
A quadratic curve can have 0, 1, or 2 distinct roots.
| C# | Copy Code |
// This quadratic has roots 1 and 2:
Quadratic quadratic1 = new Quadratic(1, -3, 2);
Double[] roots = quadratic1.FindRoots();
Console.WriteLine("Number of roots of quadratic1: {0}", roots.Length);
Console.WriteLine("Value of root 1 = {0}", roots[0]);
Console.WriteLine("Value of root 2 = {0}", roots[1]);
// This one has one double root at x = -1:
Quadratic quadratic2 = new Quadratic(1, 2, 1);
roots = quadratic2.FindRoots();
Console.WriteLine("Number of roots of quadratic3: {0}", roots.Length);
Console.WriteLine("Value of root = {0}", roots[0]); |
| Visual Basic | Copy Code |
// This quadratic has roots 1 and 2:
Dim quadratic1 As Quadratic = New Quadratic(1, -3, 2)
Dim roots As Double() = quadratic1.FindRoots()
Console.WriteLine("Number of roots of quadratic1: {0}", roots.Length)
Console.WriteLine("Value of root 1 = {0}", roots[0])
Console.WriteLine("Value of root 2 = {0}", roots[1])
// This one has one double root at x = -1:
Dim quadratic2 As Quadratic = New Quadratic(1, 2, 1)
roots = quadratic2.FindRoots()
Console.WriteLine("Number of roots of quadratic3: {0}", roots.Length)
Console.WriteLine("Value of root = {0}", roots[0]) |
The second quadratic curve has a double real root.
Up: Curves Next: Polynomials Previous: Curve Basics 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