agmorgan
Sep 20th, 2006, 06:48 AM
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 (http://www.nag.com/numeric/Fl/manual/pdf/F04/f04klf.pdf) but it crashes the IDE each time I call the routine.
Option Explicit
Option Base 1
Public Type Complex
RE As Double
IM As Double
End Type
Declare Sub F04KLF Lib "DLL20DDS.DLL" (ByRef m As Integer, _
ByRef n As Integer, ByRef p As Integer, ByRef a As Complex, _
ByRef lda As Integer, ByRef b As Complex, ByRef ldb As Integer, _
ByRef d As Complex, ByRef x As Complex, ByRef y As Complex, _
ByRef work As Complex, ByRef lwork As Integer, ByRef ifail As Integer)
Sub main()
' F04KLF Example Program Data
' 4 3 4 :Values of M, N and P
'( 0.96,-0.81) (-0.03, 0.96) (-0.91, 2.06)
'(-0.98, 1.98) (-1.20, 0.19) (-0.66, 0.42)
'( 0.62,-0.46) ( 1.01, 0.02) ( 0.63,-0.17)
'( 1.08,-0.28) ( 0.20,-0.12) (-0.07, 1.23) :End of matrix A
'( 0.50,-1.00) ( 0.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00)
'( 0.00, 0.00) ( 1.00,-2.00) ( 0.00, 0.00) ( 0.00, 0.00)
'( 0.00, 0.00) ( 0.00, 0.00) ( 2.00,-3.00) ( 0.00, 0.00)
'( 0.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00) ( 5.00,-4.00) :End of matrix B
'( 6.01,-0.37)
'(-5.27, 0.90)
'( 2.72,-2.13)
'(-1.34,-2.80) :End of D
'9.3 Program Results
' F04KLF Example Program Results
' Least-squares solution
' (-1.0000, 2.0000) ( 4.0000,-5.0000) (-3.0000, 1.0000)
Dim m As Integer
Dim n As Integer
Dim p As Integer
Dim a(4, 3) As Complex
Dim lda As Integer
Dim b(4, 4) As Complex
Dim ldb As Integer
Dim d(4) As Complex
Dim x() As Complex
Dim y() As Complex
Dim work() As Complex
Dim lwork As Integer
Dim ifail As Integer
ifail = 1
m = 4
n = 3
p = 4
ReDim x(p)
ReDim y(p)
lwork = n + m + 64 * (m + p)
ReDim work(lwork)
lda = m
ldb = m
'( 0.96,-0.81) (-0.03, 0.96) (-0.91, 2.06)
'(-0.98, 1.98) (-1.20, 0.19) (-0.66, 0.42)
'( 0.62,-0.46) ( 1.01, 0.02) ( 0.63,-0.17)
'( 1.08,-0.28) ( 0.20,-0.12) (-0.07, 1.23)
a(1, 1).RE = 0.96: a(1, 1).IM = -0.81
a(1, 2).RE = -0.03: a(1, 2).IM = 0.96
a(1, 3).RE = -0.91: a(1, 3).IM = 2.06
a(2, 1).RE = -0.98: a(2, 1).IM = 1.98
a(2, 2).RE = -1.2: a(2, 2).IM = 0.19
a(2, 3).RE = -0.66: a(2, 3).IM = 0.42
a(3, 1).RE = 0.62: a(3, 1).IM = -0.46
a(3, 2).RE = 1.01: a(3, 2).IM = 0.02
a(3, 3).RE = 0.63: a(3, 3).IM = -0.17
a(4, 1).RE = 1.08: a(4, 1).IM = -0.28
a(4, 2).RE = 0.2: a(4, 2).IM = -0.12
a(4, 3).RE = -0.07: a(4, 3).IM = 1.23
'( 0.50,-1.00) ( 0.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00)
'( 0.00, 0.00) ( 1.00,-2.00) ( 0.00, 0.00) ( 0.00, 0.00)
'( 0.00, 0.00) ( 0.00, 0.00) ( 2.00,-3.00) ( 0.00, 0.00)
'( 0.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00) ( 5.00,-4.00)
b(1, 1).RE = 0.5: b(1, 1).IM = -1#
b(1, 2).RE = 0#: b(1, 2).IM = 0#
b(1, 3).RE = 0#: b(1, 3).IM = 0#
b(1, 4).RE = 0#: b(1, 4).IM = 0#
b(2, 1).RE = 0#: b(2, 1).IM = 0#
b(2, 2).RE = 1#: b(2, 2).IM = -2#
b(2, 3).RE = 0#: b(2, 3).IM = 0#
b(2, 4).RE = 0#: b(2, 4).IM = 0#
b(3, 1).RE = 0#: b(3, 1).IM = 0#
b(3, 2).RE = 0#: b(3, 2).IM = 0#
b(3, 3).RE = 2#: b(3, 3).IM = -3#
b(3, 4).RE = 0#: b(3, 4).IM = 0#
b(4, 1).RE = 0#: b(4, 1).IM = 0#
b(4, 2).RE = 0#: b(4, 2).IM = 0#
b(4, 3).RE = 0#: b(4, 3).IM = 0#
b(4, 4).RE = 5#: b(4, 4).IM = -4#
'( 6.01,-0.37)
'(-5.27, 0.90)
'( 2.72,-2.13)
'(-1.34,-2.80)
d(1).RE = 6.01: d(1).IM = -0.37
d(2).RE = -5.27: d(2).IM = 0.9
d(3).RE = 2.72: d(3).IM = -2.13
d(4).RE = -1.34: d(4).IM = -2.8
Call F04KLF(m, n, p, a(1, 1), lda, b(1, 1), ldb, d(1), x(1), y(1), work(1), lwork, ifail)
MsgBox "Done"
End Sub
I'm trying to do a least squares solving algorithm without much luck.
I'm trying to follow the example in the instructions (http://www.nag.com/numeric/Fl/manual/pdf/F04/f04klf.pdf) but it crashes the IDE each time I call the routine.
Option Explicit
Option Base 1
Public Type Complex
RE As Double
IM As Double
End Type
Declare Sub F04KLF Lib "DLL20DDS.DLL" (ByRef m As Integer, _
ByRef n As Integer, ByRef p As Integer, ByRef a As Complex, _
ByRef lda As Integer, ByRef b As Complex, ByRef ldb As Integer, _
ByRef d As Complex, ByRef x As Complex, ByRef y As Complex, _
ByRef work As Complex, ByRef lwork As Integer, ByRef ifail As Integer)
Sub main()
' F04KLF Example Program Data
' 4 3 4 :Values of M, N and P
'( 0.96,-0.81) (-0.03, 0.96) (-0.91, 2.06)
'(-0.98, 1.98) (-1.20, 0.19) (-0.66, 0.42)
'( 0.62,-0.46) ( 1.01, 0.02) ( 0.63,-0.17)
'( 1.08,-0.28) ( 0.20,-0.12) (-0.07, 1.23) :End of matrix A
'( 0.50,-1.00) ( 0.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00)
'( 0.00, 0.00) ( 1.00,-2.00) ( 0.00, 0.00) ( 0.00, 0.00)
'( 0.00, 0.00) ( 0.00, 0.00) ( 2.00,-3.00) ( 0.00, 0.00)
'( 0.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00) ( 5.00,-4.00) :End of matrix B
'( 6.01,-0.37)
'(-5.27, 0.90)
'( 2.72,-2.13)
'(-1.34,-2.80) :End of D
'9.3 Program Results
' F04KLF Example Program Results
' Least-squares solution
' (-1.0000, 2.0000) ( 4.0000,-5.0000) (-3.0000, 1.0000)
Dim m As Integer
Dim n As Integer
Dim p As Integer
Dim a(4, 3) As Complex
Dim lda As Integer
Dim b(4, 4) As Complex
Dim ldb As Integer
Dim d(4) As Complex
Dim x() As Complex
Dim y() As Complex
Dim work() As Complex
Dim lwork As Integer
Dim ifail As Integer
ifail = 1
m = 4
n = 3
p = 4
ReDim x(p)
ReDim y(p)
lwork = n + m + 64 * (m + p)
ReDim work(lwork)
lda = m
ldb = m
'( 0.96,-0.81) (-0.03, 0.96) (-0.91, 2.06)
'(-0.98, 1.98) (-1.20, 0.19) (-0.66, 0.42)
'( 0.62,-0.46) ( 1.01, 0.02) ( 0.63,-0.17)
'( 1.08,-0.28) ( 0.20,-0.12) (-0.07, 1.23)
a(1, 1).RE = 0.96: a(1, 1).IM = -0.81
a(1, 2).RE = -0.03: a(1, 2).IM = 0.96
a(1, 3).RE = -0.91: a(1, 3).IM = 2.06
a(2, 1).RE = -0.98: a(2, 1).IM = 1.98
a(2, 2).RE = -1.2: a(2, 2).IM = 0.19
a(2, 3).RE = -0.66: a(2, 3).IM = 0.42
a(3, 1).RE = 0.62: a(3, 1).IM = -0.46
a(3, 2).RE = 1.01: a(3, 2).IM = 0.02
a(3, 3).RE = 0.63: a(3, 3).IM = -0.17
a(4, 1).RE = 1.08: a(4, 1).IM = -0.28
a(4, 2).RE = 0.2: a(4, 2).IM = -0.12
a(4, 3).RE = -0.07: a(4, 3).IM = 1.23
'( 0.50,-1.00) ( 0.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00)
'( 0.00, 0.00) ( 1.00,-2.00) ( 0.00, 0.00) ( 0.00, 0.00)
'( 0.00, 0.00) ( 0.00, 0.00) ( 2.00,-3.00) ( 0.00, 0.00)
'( 0.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00) ( 5.00,-4.00)
b(1, 1).RE = 0.5: b(1, 1).IM = -1#
b(1, 2).RE = 0#: b(1, 2).IM = 0#
b(1, 3).RE = 0#: b(1, 3).IM = 0#
b(1, 4).RE = 0#: b(1, 4).IM = 0#
b(2, 1).RE = 0#: b(2, 1).IM = 0#
b(2, 2).RE = 1#: b(2, 2).IM = -2#
b(2, 3).RE = 0#: b(2, 3).IM = 0#
b(2, 4).RE = 0#: b(2, 4).IM = 0#
b(3, 1).RE = 0#: b(3, 1).IM = 0#
b(3, 2).RE = 0#: b(3, 2).IM = 0#
b(3, 3).RE = 2#: b(3, 3).IM = -3#
b(3, 4).RE = 0#: b(3, 4).IM = 0#
b(4, 1).RE = 0#: b(4, 1).IM = 0#
b(4, 2).RE = 0#: b(4, 2).IM = 0#
b(4, 3).RE = 0#: b(4, 3).IM = 0#
b(4, 4).RE = 5#: b(4, 4).IM = -4#
'( 6.01,-0.37)
'(-5.27, 0.90)
'( 2.72,-2.13)
'(-1.34,-2.80)
d(1).RE = 6.01: d(1).IM = -0.37
d(2).RE = -5.27: d(2).IM = 0.9
d(3).RE = 2.72: d(3).IM = -2.13
d(4).RE = -1.34: d(4).IM = -2.8
Call F04KLF(m, n, p, a(1, 1), lda, b(1, 1), ldb, d(1), x(1), y(1), work(1), lwork, ifail)
MsgBox "Done"
End Sub