Extreme Optimization™: Complexity made simple.

Numerical Components
for .NET

  • Home
  • •
  • Features
    • Math Library
    • Vector and Matrix Library
    • Statistics Library
    • Performance
    • Usability
  • •
  • Documentation
    • Introduction
    • Math Library User's Guide
    • Vector and Matrix Library User's Guide
    • Statistics Library User's Guide
    • Reference
  • •
  • Support
    • Frequently Asked Questions
    • QuickStart Samples
    • Sample Applications
    • Downloads
  • •
  • Blog
  • •
  • Company
    • About us
    • Testimonials
    • Customers
    • Press Releases
    • Careers
    • Contact us
Introduction
Expand Mathematics Library User's GuideMathematics Library User's Guide
Expand Vector and Matrix Library User's GuideVector and Matrix Library User's Guide
Expand Statistics Library User's GuideStatistics Library User's Guide
Expand ReferenceReference
  • Home
  • Documentation
  • Mathematics Library User's Guide
  • Curves
  • Simple Curves
Collapse imageExpand ImageCopy imageCopyHover image
       




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 imageCopy
Constant constant1 = new Constant(3);
Constant constant2 = Constant.Zero;
Visual Basic Copy imageCopy
Dim constant1 As Constant = New Constant(3)
Dim constant2 As Constant = Constant.Zero

The ValueAt(Double) method returns the constant value of the curve. SlopeAt(Double) always returns zero. Integral(Double, Double) 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 imageCopy
// 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 imageCopy

' 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 imageCopy
Line line3 = new Line(point1, 2);
Line line4 = new Line(point1.X, point1.Y, 2);
Visual Basic Copy imageCopy
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 imageCopy
Line line5 = new Line(2, 1);
Visual Basic Copy imageCopy
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(Double) method returns the value of the line at a specific point. SlopeAt(Double) returns the constant slope of the Line. Integral(Double, Double) 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 imageCopy
Line line1 = new Line(1, 1, 2);
double root = line1.FindRoots()[0];
Visual Basic Copy imageCopy
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 imageCopy
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 imageCopy
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 imageCopy
Quadratic quadratic2 = new Quadratic(point1.X, point1.Y, 
    point2.X, point2.Y, point3.X, point3.Y);
Visual Basic Copy imageCopy
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 imageCopy
Quadratic quadratic3 = new Quadratic(1, 2, 1);
Visual Basic Copy imageCopy
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(Double) method returns the value of the line at a specific point. SlopeAt(Double) returns the slope of the Quadratic. Integral(Double, Double) 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 imageCopy
// 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 imageCopy
// 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.

Send comments on this topic to support@extremeoptimization.com

Copyright © 2003-2010, 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 Optimized for Visual Studio logo
are registered trademarks of Microsoft Corporation.