Does anyone use the NAG (Numerical Algorithms Group) libraries?
I'm trying to do a least squares solving algorithm without much luck.
I'm trying to follow the example in the instructions but it crashes the IDE each time I call the routine.
VB Code:
  1. Option Explicit
  2. Option Base 1
  3.  
  4. Public Type Complex
  5.     RE As Double
  6.     IM As Double
  7. End Type
  8.  
  9.  
  10.     Declare Sub F04KLF Lib "DLL20DDS.DLL" (ByRef m As Integer, _
  11.   ByRef n As Integer, ByRef p As Integer, ByRef a As Complex, _
  12.   ByRef lda As Integer, ByRef b As Complex, ByRef ldb As Integer, _
  13.   ByRef d As Complex, ByRef x As Complex, ByRef y As Complex, _
  14.   ByRef work As Complex, ByRef lwork As Integer, ByRef ifail As Integer)
  15.  
  16.  
  17.  
  18.    Sub main()
  19.  
  20.  
  21.  
  22.         '        F04KLF Example Program Data
  23.         '  4  3  4                                               :Values of M, N and P
  24.         '( 0.96,-0.81) (-0.03, 0.96) (-0.91, 2.06)
  25.         '(-0.98, 1.98) (-1.20, 0.19) (-0.66, 0.42)
  26.         '( 0.62,-0.46) ( 1.01, 0.02) ( 0.63,-0.17)
  27.         '( 1.08,-0.28) ( 0.20,-0.12) (-0.07, 1.23)               :End of matrix A
  28.         '( 0.50,-1.00) ( 0.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00)
  29.         '( 0.00, 0.00) ( 1.00,-2.00) ( 0.00, 0.00) ( 0.00, 0.00)
  30.         '( 0.00, 0.00) ( 0.00, 0.00) ( 2.00,-3.00) ( 0.00, 0.00)
  31.         '( 0.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00) ( 5.00,-4.00) :End of matrix B
  32.         '( 6.01,-0.37)
  33.         '(-5.27, 0.90)
  34.         '( 2.72,-2.13)
  35.         '(-1.34,-2.80)                                           :End of D
  36.  
  37.         '9.3  Program Results
  38.         ' F04KLF Example Program Results
  39.  
  40.         ' Least-squares solution
  41.         '    (-1.0000, 2.0000) ( 4.0000,-5.0000) (-3.0000, 1.0000)
  42.        
  43.        
  44.         Dim m As Integer
  45.         Dim n As Integer
  46.         Dim p As Integer
  47.         Dim a(4, 3) As Complex
  48.         Dim lda As Integer
  49.         Dim b(4, 4) As Complex
  50.         Dim ldb As Integer
  51.         Dim d(4) As Complex
  52.         Dim x() As Complex
  53.         Dim y() As Complex
  54.         Dim work() As Complex
  55.         Dim lwork As Integer
  56.         Dim ifail As Integer
  57.  
  58.         ifail = 1
  59.  
  60.         m = 4
  61.         n = 3
  62.         p = 4
  63.         ReDim x(p)
  64.         ReDim y(p)
  65.         lwork = n + m + 64 * (m + p)
  66.         ReDim work(lwork)
  67.         lda = m
  68.         ldb = m
  69.  
  70.         '( 0.96,-0.81) (-0.03, 0.96) (-0.91, 2.06)
  71.         '(-0.98, 1.98) (-1.20, 0.19) (-0.66, 0.42)
  72.         '( 0.62,-0.46) ( 1.01, 0.02) ( 0.63,-0.17)
  73.         '( 1.08,-0.28) ( 0.20,-0.12) (-0.07, 1.23)
  74.  
  75.         a(1, 1).RE = 0.96:   a(1, 1).IM = -0.81
  76.         a(1, 2).RE = -0.03:  a(1, 2).IM = 0.96
  77.         a(1, 3).RE = -0.91:  a(1, 3).IM = 2.06
  78.  
  79.         a(2, 1).RE = -0.98:  a(2, 1).IM = 1.98
  80.         a(2, 2).RE = -1.2:   a(2, 2).IM = 0.19
  81.         a(2, 3).RE = -0.66:  a(2, 3).IM = 0.42
  82.        
  83.         a(3, 1).RE = 0.62:   a(3, 1).IM = -0.46
  84.         a(3, 2).RE = 1.01:   a(3, 2).IM = 0.02
  85.         a(3, 3).RE = 0.63:   a(3, 3).IM = -0.17
  86.        
  87.         a(4, 1).RE = 1.08:   a(4, 1).IM = -0.28
  88.         a(4, 2).RE = 0.2:    a(4, 2).IM = -0.12
  89.         a(4, 3).RE = -0.07:  a(4, 3).IM = 1.23
  90.  
  91.  
  92.         '( 0.50,-1.00) ( 0.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00)
  93.         '( 0.00, 0.00) ( 1.00,-2.00) ( 0.00, 0.00) ( 0.00, 0.00)
  94.         '( 0.00, 0.00) ( 0.00, 0.00) ( 2.00,-3.00) ( 0.00, 0.00)
  95.         '( 0.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00) ( 5.00,-4.00)
  96.         b(1, 1).RE = 0.5: b(1, 1).IM = -1#
  97.         b(1, 2).RE = 0#: b(1, 2).IM = 0#
  98.         b(1, 3).RE = 0#: b(1, 3).IM = 0#
  99.         b(1, 4).RE = 0#: b(1, 4).IM = 0#
  100.  
  101.         b(2, 1).RE = 0#: b(2, 1).IM = 0#
  102.         b(2, 2).RE = 1#: b(2, 2).IM = -2#
  103.         b(2, 3).RE = 0#: b(2, 3).IM = 0#
  104.         b(2, 4).RE = 0#: b(2, 4).IM = 0#
  105.  
  106.         b(3, 1).RE = 0#: b(3, 1).IM = 0#
  107.         b(3, 2).RE = 0#: b(3, 2).IM = 0#
  108.         b(3, 3).RE = 2#: b(3, 3).IM = -3#
  109.         b(3, 4).RE = 0#: b(3, 4).IM = 0#
  110.  
  111.         b(4, 1).RE = 0#: b(4, 1).IM = 0#
  112.         b(4, 2).RE = 0#: b(4, 2).IM = 0#
  113.         b(4, 3).RE = 0#: b(4, 3).IM = 0#
  114.         b(4, 4).RE = 5#: b(4, 4).IM = -4#
  115.  
  116.         '( 6.01,-0.37)
  117.         '(-5.27, 0.90)
  118.         '( 2.72,-2.13)
  119.         '(-1.34,-2.80)
  120.         d(1).RE = 6.01:  d(1).IM = -0.37
  121.         d(2).RE = -5.27: d(2).IM = 0.9
  122.         d(3).RE = 2.72:  d(3).IM = -2.13
  123.         d(4).RE = -1.34: d(4).IM = -2.8
  124.  
  125.  
  126.         Call F04KLF(m, n, p, a(1, 1), lda, b(1, 1), ldb, d(1), x(1), y(1), work(1), lwork, ifail)
  127.         MsgBox "Done"
  128.     End Sub