Search code examples
vb.netmathintegrate

how to use Integrate.OnClosedInterval of the library Math.Net in VB?


I read the documentation of Mathdotnet but is unintelligible. I don't understand how to use it at all. I would like to integrate the density function of a gamma distribution to get a conditionnal expectation.

I found this exemple in C# but it does not work in VB. To compare with the exemple above, I would like to do something like this:

MathNet.Numerics.Integrate.OnClosedInterval(x >= Gamma.PDF(alpha, beta, x), 0, p / 100)

What would be the equivalent in VB?


Solution

  • If I am getting your question correct then I will suggest there should be lambda expression symbol (=>) in your code (I tried to edit it but it was rejected)

    1. It's required to Import MathNet.Numerics and MathNet.Numerics.Distributions Namespaces. For that you have to download it.
    2. There's Lambda expression as First parameter of OnClosedInterval() so you have to do like Function(a) in vb.net

    your vb.net code can be like this,

    Imports System
    Imports MathNet.Numerics
    Imports MathNet.Numerics.Distributions
    
    Public Module Module1
      Public Sub Main()
        Console.WriteLine(Integrate.OnClosedInterval(Function(a) Gamma.PDF(alpha, beta, a), 0, p/100))
      End Sub
    End Module
    

    You can see example here