Extreme Optimization >
QuickStart Samples >
Constant Curve QuickStart Sample (C#)
Extreme Optimization QuickStart Samples
Constant Curve 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.
/// </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();
}
}
}
Copyright 2004-2007,
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, and Visual
Studio.NET are registered trademarks of Microsoft Corporation