Extreme Optimization > QuickStart Samples > Line Curve QuickStart Sample (C#)

Extreme Optimization QuickStart Samples

Line Curve QuickStart Sample (C#)

Illustrates the use of the Point structure and Line class (Extreme.Mathematics.Curves namespace) in C#.

VB.NET code Back to QuickStart Samples

using System;

namespace Extreme.Mathematics.QuickStart.CSharp
{
    // The Point structure and Line class reside in the 
    // Extreme.Mathematics.Curves namespace.
    using Extreme.Mathematics.Curves;

    /// <summary>
    /// Illustrates the use of the Point structure and the Line
    /// class in the Extreme.Mathematics.Curve namespace of the Extreme
    /// Optimization Mathematics Library for .NET.
    /// </summary>
    class LineCurves
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            // All curves inherit from the Curve abstract base
            // class. The Line class overrides implements all
            // the methods and properties of the Curve class,
            // and adds a few more.
            //
            // In a few places, we will need the Point structure.
            // It simply containts an X and a Y component, much
            // like the PointF structure in the System.Drawing
            // namespace.
            //
            // Let's create some points:
            Point point1 = new Point(1, 3);
            Point point2 = new Point(4, 9);

            //
            // Line constructors
            //

            // The Line class has multiple constructors. Each
            // constructor derives from a different way to define
            // a straight line.

            // 1st option: a line through 2 points.
            Line line1 = new Line(point1, point2);
            // 2nd option: same as above, but we use the x and 
            // y coordinates of the points directly.
            Line line2 = new Line(point1.X, point1.Y, point2.X, point2.Y);
            // 3rd option: a line through a point with a specified
            // slope,
            Line line3 = new Line(point1, 2);
            // 4th option: same as above, but we use the x and 
            // y coordinates of the point directly.
            Line line4 = new Line(point1.X, point1.Y, 2);
            // 5th option: a line with specified slope and 
            // specified value at x = 0
            Line line5 = new Line(2, 1);

            //
            // Curve Parameters
            //

            // The shape of any curve is determined by a set of parameters.
            // These parameters can be retrieved and set through the
            // Parameters collection. The number of parameters for a curve
            // is given by this collection's Count property.
            //
            // Lines have two parameters: the y value at x = 0
            // and the slope.
            Console.WriteLine("line1.Parameters.Count = {0}", 
                line1.Parameters.Count);
            // Parameters can easily be retrieved:
            Console.WriteLine("line1 parameters; {0}, {1}", 
                line1.Parameters[0], line1.Parameters[1]);
            // We can see that line2, line3, line4 and line5
            // all define the same line as line1:
            Console.WriteLine("line2 parameters; {0}, {1}", 
                line2.Parameters[0], line2.Parameters[1]);
            Console.WriteLine("line3 parameters; {0}, {1}", 
                line3.Parameters[0], line3.Parameters[1]);
            Console.WriteLine("line4 parameters; {0}, {1}", 
                line4.Parameters[0], line4.Parameters[1]);
            Console.WriteLine("line5 parameters; {0}, {1}", 
                line5.Parameters[0], line5.Parameters[1]);
            // Parameters can also be set:
            line1.Parameters[0] = 1;

            //
            // Curve Methods
            //

            // The ValueAt method returns the y value of the
            // curve at the specified x value:
            Console.WriteLine("line1.ValueAt(2) = {0}", line1.ValueAt(2));

            // The SlopeAt method returns the slope of the curve
            // a the specified x value:
            Console.WriteLine("line1.SlopeAt(2) = {0}", line1.SlopeAt(2));

            // You can also create a new curve that is the 
            // derivative of the original:
            Curve derivative = line1.GetDerivative();
            Console.WriteLine("Slope at 2 (derivative) = {0}", derivative.ValueAt(2));

            // For Line curves, you can access the slope directly
            // through the Slope property:
            Console.WriteLine("Slope of the line = {0}", line1.Slope);

            // You can get a Line that is the tangent to a curve
            // at a specified x value using the TangentAt method:
            Line tangent = line1.TangentAt(2);
            Console.WriteLine("Slope of tangent line at 2 = {0}",
                tangent.Slope);

            // For many curves, you can evaluate a definite
            // integral exactly:
            Console.WriteLine("Integral of line1 between 0 and 1 = {0}",
                line1.Integral(0, 1));

            // You can find the zeroes or roots of the curve
            // by calling the FindRoots method:
            double[] roots = line1.FindRoots();
            Console.WriteLine("Number of roots of line1: {0}",
                roots.Length);
            Console.WriteLine("Value of root = {0}", roots[0]);

            Console.Write("Press Enter key to exit...");
            Console.ReadLine();
        }
    }
}
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