New Version 5.0!

Try it for free with our fully functional 60-day trial version.

Download now!

QuickStart Samples

Quasi-Random Sequences QuickStart Sample (Visual Basic)

Illustrates how to generate quasi-random sequences like Fauré and Sobol sequences using classes in the Extreme.Statistics.Random namespace in Visual Basic.

C# code F# code IronPython code Back to QuickStart Samples

Imports Extreme.Mathematics
Imports Extreme.Mathematics.LinearAlgebra
Imports Extreme.Statistics.Random

Namespace Extreme.Numerics.QuickStart.VB
    ' Illustrates the use of quasi-random sequences by computing
    ' a multi-dimensional integral.
    Module QuasiRandom

        Sub Main()
            ' This QuickStart Sample demonstrates the use of
            ' quasi-random sequences by computing
            ' a multi-dimensional integral.

            ' We will use one million points.
            Dim capacity As Integer = 10000
            ' The number of dimensions:
            Dim dimension As Integer = 5

            ' We will evaluate the function
            '
            '    Product(i = 1 -> # dimensions) |4 x(i) - 2|
            '
            ' over the hypercube 0 <= x(i) <= 1. The value of this integral
            ' is exactly 1.

            ' This vector will hold the current vector in the sequence:
            Dim point As DenseVector = Vector.Create(dimension)
            ' Create the sequence:
            Dim sequence As HaltonSequence = New HaltonSequence(point, capacity)

            Console.WriteLine("# iter.  Estimate")
            ' Compute the integral by summing over all points:
            Dim sum As Double = 0.0

            For i As Integer = 1 To capacity - 1

                If (i Mod 1000 = 0) Then
                    Console.WriteLine("{0,6}  {1,8:F4}", i, sum / i)
                End If

                ' Evaluate the integrand:
                Dim functionValue As Double = 1.0
                For j As Integer = 0 To dimension - 1
                    functionValue *= Math.Abs(4.0 * point(j) - 2.0)
                Next
                sum += functionValue

                sequence.MoveNext()
            Next

            ' Print the final result.
            Console.WriteLine("Final estimate: {0,8:F4}", sum / capacity)
            Console.WriteLine("Exact value: 1.0000")

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

        End Sub

    End Module

End Namespace