Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Wrapping C with C++ in .NET


January 04:

Listing 5: Using the numeric objects from VB.NET.

Imports System
Imports System.Runtime.InteropServices
Imports NAGLIB

Module Module1
   Public Class DCLASS
      Inherits NAG_FUNCTIONS
      Public Function the_integrand_c(ByVal x As Double) As Double
         Dim pi As Double
         Dim val As Double
         pi = Math.PI
         val = (x * Math.Sin(x * 30) / 1 - x * x / (pi * pi * 4))
         Return val
      End Function
   End Class
   Sub Main()
      Dim x, the_answer As Double
      Dim flag, j, tda, n As Integer
      Dim a(,), r(), a1, b1, abserr As Double
      Dim tt As New DCLASS()
      Dim myfun As New INTEGRAND_FUN_TYPE(AddressOf tt.the_integrand_c)
      a1 = 0
      b1 = Math.PI * 2
      flag = 0
      tt.QUADRATURE(a1, b1, the_answer, abserr, flag, myfun)
      Console.WriteLine("The integral (default number of 
                                     subintervals) = {0,8:F4}", the_answer)
      tt.QUADRATURE_max_subint = 3
      flag = 0
      tt.QUADRATURE(a1, b1, the_answer, abserr, flag, myfun)
      Console.WriteLine("The integral (number of subintervals 
                                     set to 3) = {0,8:F4}", the_answer)
      x = -1
      the_answer = tt.CUM_NORM(x)
      Console.WriteLine("The value of the cumulative  normal = {0,8:F4}", the_answer)
      flag = 0
      n = 4
      tda = n
      ReDim r(n - 1)
      ReDim a(n - 1, n - 1)
      ' first row
      a(0, 0) = 0.5
      a(0, 1) = 0
      a(0, 2) = 2.3
      a(0, 3) = -2.6
      'second row
      a(1, 0) = 0
      a(1, 1) = 0.5
      a(1, 2) = -1.4
      a(1, 3) = -0.7
      ' third row
      a(2, 0) = 2.3
      a(2, 1) = -1.4
      a(2, 2) = 0.5
      a(2, 3) = 0
     'fourth row
     a(3, 0) = -2.6
     a(3, 1) = -0.7
     a(3, 2) = 0
     a(3, 3) = 0.5
     tt.REAL_SYMM_EIGEN(n, a(0, 0), tda, r(0), flag)
     Console.Write("The Eigenvalues are:")
     For j = 0 To n - 1
        Console.Write("{0,8:F4}", r(j))
     Next j
     Console.WriteLine()
  End Sub
End Module




	
		

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.