Extreme Optimization > Mathematics Library for .NET > QuickStart Samples > ConstantCurve QuickStart Sample (C#)

Extreme Optimization Mathematics Library for .NET

ConstantCurve QuickStart Sample (C#)

Illustrates the use of the Constant class (Extreme.Mathematics.Curves namespace) in C#.

VB.NET code Back to QuickStart Samples

using System;

namespace Extreme.Mathematics.QuickStart.CSharp
{
    // The Constant and Line classes resides in the 
    // Extreme.Mathematics.Curves namespace.
    using Extreme.Mathematics.Curves;

    /// <summary>
    /// Illustrates the use of the Constant class in the
    /// Extreme.Mathematics.Curve namespace of the Extreme Optimization 
    /// Mathematics Library for .NET.
    /// </summary>
    class ConstantCurve
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            // All curves inherit from the Curve abstract base
            // class. It cannot be instantiated. This class 
            // defines methods and properties that are available
            // to all derived types, including Constant, Line,
            // Quadratic, Polynomial, ChebyshevExpansion and
            // LinearFunction.
            //
            // This QuickStart sample illustrates the Constant
            // and Line classes.
            //

            // 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);

            // 
            // Creating Constant curves.
            //

            // Let's start by creating a Constant curve and some 
            // Line curves.
            // A Constant curve has the same value everywhere.
            Constant constant1 = new Constant(3);
            // There is one predefined Constant curve, which is
            // zero everywhere:
            Constant constant2 = Constant.Zero;

            //
            // 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.
            //
            // Constants have one parameter: the y value.
            Console.WriteLine("constant1.Parameters.Count = {0}", 
                constant1.Parameters.Count);
            // Parameters can easily be retrieved:
            Console.WriteLine("constant1.Parameters[0] = {0}", 
                constant1.Parameters[0]);
            // Parameters can also be set:
            constant1.Parameters[0] = 3;

            //
            // Curve Methods
            //

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

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

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

            // You can get a Line that is the tangent to a curve
            // at a specified x value using the TangentAt method:
            Line tangent = constant1.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 constant1 between 0 and 1 = {0}",
                constant1.Integral(0, 1));

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

            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
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