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# CopyCode imageCopy Code
Constant constant1 = new Constant(3);
Constant constant2 = Constant.Zero;
Visual Basic CopyCode imageCopy 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# CopyCode imageCopy 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 CopyCode imageCopy 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# CopyCode imageCopy Code
Line line3 = new Line(point1, 2);
Line line4 = new Line(point1.X, point1.Y, 2);
Visual Basic CopyCode imageCopy 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# CopyCode imageCopy Code
Line line5 = new Line(2, 1);
Visual Basic CopyCode imageCopy 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# CopyCode imageCopy Code
Line line1 = new Line(1, 1, 2);
double root = line1.FindRoots()[0];
Visual Basic CopyCode imageCopy 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# CopyCode imageCopy 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 CopyCode imageCopy 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# CopyCode imageCopy Code
Quadratic quadratic2 = new Quadratic(point1.X, point1.Y, 
    point2.X, point2.Y, point3.X, point3.Y);
Visual Basic CopyCode imageCopy 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# CopyCode imageCopy Code
Quadratic quadratic3 = new Quadratic(1, 2, 1);
Visual Basic CopyCode imageCopy 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# CopyCode imageCopy 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 CopyCode imageCopy 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

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