Extreme Optimization >
QuickStart Samples >
Constant Curve QuickStart Sample (VB.NET)
Extreme Optimization QuickStart Samples
Constant Curve QuickStart Sample (VB.NET)
Illustrates the use of the Constant class (Extreme.Mathematics.Curves
namespace) in Visual Basic .NET.
C# code Back
to QuickStart Samples
' The Constant class resides in the Extreme.Mathematics.Curves namespace.
Imports Extreme.Mathematics.Curves
Namespace Extreme.Mathematics.QuickStart.VB
' Illustrates the use of the ConstantCurve class in the.
' Extreme.Mathematics.Curves namespace.
Module ConstantCurve
Sub Main()
' 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, ChebyshevSeries and
' LinearFunction.
'
' This QuickStart sample illustrates the Constant
' class.
'
' Creating Constant curves.
'
' Let's start by creating a Constant curve and some
' Line curves.
' A Constant curve has the same value everywhere.
Dim constant1 As Constant = New Constant(3)
' There is one predefined Constant curve, which is
' zero everywhere:
Dim constant2 As Constant = 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:
Dim derivative As Curve = 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:
Dim tangent As Line = 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 between 0 and 1 = {0}", _
constant1.Integral(0, 1))
' You can find the zeroes or roots of the curve
' by calling the FindRoots method:
Dim roots As Double() = constant1.FindRoots()
Console.WriteLine("constant1 curve has {0} roots.", _
roots.Length)
Console.Write("Press Enter key to exit...")
Console.ReadLine()
End Sub
End Module
End Namespace
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