Extreme Optimization > QuickStart Samples > Line Curve QuickStart Sample (VB.NET)

Extreme Optimization QuickStart Samples

Line Curve QuickStart Sample (VB.NET)

Illustrates the use of the Point structure and Line class (Extreme.Mathematics.Curves namespace) in Visual Basic .NET.

C# code Back to QuickStart Samples

' The Point structure and Line class reside in the 
' Extreme.Mathematics.Curves namespace.
Imports Extreme.Mathematics.Curves

Namespace Extreme.Mathematics.QuickStart.VB

    Module LineCurve

        ' 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.
        Sub Main()
            ' 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:
            Dim point1 As Point = New Point(1, 3)
            Dim point2 As Point = 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.
            Dim line1 As Line = New Line(point1, point2)
            ' 2nd option: same as above, but we use the x and 
            ' y coordinates of the points directly.
            Dim line2 As Line = New Line(point1.X, point1.Y, _
                point2.X, point2.Y)
            ' 3rd option: a line through a point with a specified
            ' slope,
            Dim line3 As Line = New Line(point1, 2)
            ' 4th option: same as above, but we use the x and 
            ' y coordinates of the point directly.
            Dim line4 As Line = New Line(point1.x, point1.y, 2)
            ' 5th option: a line with specified slope and 
            ' specified value at x = 0
            Dim line5 As Line = 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:
            Dim derivative As Curve = 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:
            Dim tangent As Line = 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 between 0 and 1 = {0}", _
                line1.Integral(0, 1))

            ' You can find the zeroes or roots of the curve
            ' by calling the FindRoots method:
            Dim roots As Double() = line1.FindRoots()
            Console.WriteLine("line1 has {0} roots.", _
                roots.Length)
            Console.WriteLine("Value of root = {0}", roots(0))

            Console.Write("Press Enter key to exit...")
            Console.ReadLine()

        End Sub

    End Module

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