⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 piecewisecurves.vb

📁 这里是用VB写的数学库。以前用C、C++写的比较多。内容有:复数运算、矩阵运算、解方程、积分微分等。非常有用。
💻 VB
字号:
' The piecewise curve classes reside in the 
' Extreme.Mathematics.Curves namespace.
Imports Extreme.Mathematics.Curves
Imports Extreme.Mathematics.LinearAlgebra

Namespace Extreme.Mathematics.QuickStart.VB
    ' Illustrates the use of the PiecewiseConstantCurve and
    ' PiecewiseLinearCurve classes.
    Module NumericalDifferentiation

        Sub Main()
            ' A piecewise curve is a curve that has a different definition
            ' on subintervals of its domain.
            ' 
            ' This QuickStart Sample illustrates constant and linear piecewise
            ' curves, which - as the name suggest - are constant or linear
            ' on each interval.
            '
            ' For an example of cubic splines, see the CubicSplines QuickStart 
            ' Sample.
            '

            ' 
            ' Piecewise constants
            '

            ' All piecewise curves inherit from the PiecewiseCurve class.
            ' Piecewise constant curves are implemented by the
            ' PiecewiseConstantCurve class. It has three constructors.

            ' The first constructor takes two double arrays as parameters.
            ' These contain the x and y values of the data points:
            Dim xValues As Double() = {1, 2, 3, 4, 5, 6}
            Dim yValues As Double() = {1, 3, 4, 3, 4, 2}
            Dim constant1 As PiecewiseConstantCurve = New PiecewiseConstantCurve(xValues, yValues)

            ' The second constructor takes two Vector objects, containing the
            ' x and y-values of the data points:
            Dim xVector As GeneralVector = New GeneralVector(xValues)
            Dim yVector As GeneralVector = New GeneralVector(yValues)
            Dim constant2 As PiecewiseConstantCurve = New PiecewiseConstantCurve(xVector, yVector)

            ' The third constructor only takes one parameter: an array of
            ' Point structures that represent the data point.
            Dim dataPoints As Point() = New Point() _
                {New Point(1, 1), New Point(2, 3), New Point(3, 4), _
                 New Point(4, 3), New Point(5, 4), New Point(6, 2)}
            Dim constant3 As PiecewiseConstantCurve = New PiecewiseConstantCurve(dataPoints)

            '
            ' 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.
            '
            ' Piecewise constant curves have 2n parameters, where n is the number of
            ' data points. The first n parameters are the x-values. The next
            ' n parameters are the y-values.

            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) = 1

            '
            ' Curve Methods
            '

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

            ' The SlopeAt method returns the slope of the curve
            ' a the specified x value:
            Console.WriteLine("constant1.SlopeAt(2.4) = {0}", constant1.SlopeAt(2.4))
            ' The slope at the data points is Double.NaN if the value of the constant
            ' is different on either side of the data point:
            Console.WriteLine("constant1.SlopeAt(2) = {0}", constant1.SlopeAt(2))

            ' Piecewise constant curves do not have a defined derivative. 
            ' The GetDerivative method returns a GeneralCurve:
            Dim derivative As Curve = constant1.GetDerivative()
            Console.WriteLine("Type of derivative: {0}", derivative.GetType().ToString())
            Console.WriteLine("derivative(2.4) = {0}", derivative.ValueAt(2.4))

            ' 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.4)
            Console.WriteLine("Slope of tangent line at 2.4 = {0}", tangent.Slope)

            ' The integral of a piecewise constant curve can be calculated exactly. 
            Console.WriteLine("Integral of constant1 between 1.4 and 4.6 = {0}", _
                constant1.Integral(1.4, 4.6))


            ' 
            ' Piecewise linear curves
            '

            ' Piecewise linear curves are used for linear interpolation
            ' between data points. They are implemented by the
            ' PiecewiseLinearCurve class. It has three constructors,
            ' similar to the constructors for the PiecewiseLinearCurve
            ' class..These constructors create the linear interpolating
            ' curve between the data points.

            ' The first constructor takes two double arrays as parameters.
            ' These contain the x and y values of the data points:
            Dim xValues2 As Double() = {1, 2, 3, 4, 5, 6}
            Dim yValues2 As Double() = {1, 3, 4, 3, 4, 2}
            Dim line1 As PiecewiseLinearCurve = New PiecewiseLinearCurve(xValues2, yValues2)

            ' The second constructor takes two Vector objects, containing the
            ' x and y-values of the data points:
            Dim xVector2 As GeneralVector = New GeneralVector(xValues2)
            Dim yVector2 As GeneralVector = New GeneralVector(yValues2)
            Dim line2 As PiecewiseLinearCurve = New PiecewiseLinearCurve(xVector2, yVector2)

            ' The third constructor only takes one parameter: an array of
            ' Point structures that represent the data point.
            Dim dataPoints2 As Point() = New Point() _
                {New Point(1, 1), New Point(2, 3), New Point(3, 4), _
                 New Point(4, 3), New Point(5, 4), New Point(6, 2)}
            Dim line3 As PiecewiseLinearCurve = New PiecewiseLinearCurve(dataPoints)

            '
            ' Curve Parameters
            '

            ' Piecewise linear curves have 2n parameters, where n is the number of
            ' data points. The first n parameters are the x-values. The next
            ' n parameters are the y-values.

			Console.WriteLine("line1.Parameters.Count = {0}", line1.Parameters.Count)
            ' Parameters can easily be retrieved:
			Console.WriteLine("line1.Parameters(0) = {0}", line1.Parameters(0))
            ' 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.4) = {0}", line1.ValueAt(2.4))

            ' The SlopeAt method returns the slope of the curve
            ' a the specified x value:
            Console.WriteLine("line1.SlopeAt(2.4) = {0}", line1.SlopeAt(2.4))
            ' The slope at the data points is Double.NaN if the slope of the line
            ' is different on either side of the data point:
            Console.WriteLine("line1.SlopeAt(2) = {0}", line1.SlopeAt(2))

            ' Piecewise line curves do not have a defined derivative. 
            ' The GetDerivative method returns a GeneralCurve:
            derivative = line1.GetDerivative()
            Console.WriteLine("Type of derivative: {0}", derivative.GetType().ToString())
            Console.WriteLine("derivative(2.4) = {0}", derivative.ValueAt(2.4))

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

            ' The integral of a piecewise line curve can be calculated exactly. 
            Console.WriteLine("Integral of line1 between 1.4 and 4.6 = {0}", _
                line1.Integral(1.4, 4.6))

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

    End Module

End Namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -