Académique Documents
Professionnel Documents
Culture Documents
Marcin Krzysztofik
2
Why NAG & Excel?
3
Why you don’t need to be a C/Fortran programmer?
4
Why you don’t need to be a C/Fortran programmer?
5
NAG C Library vs. NAG Fortran Library
A function can be called either from NAG Fortran
Library or NAG C Library. What are the differences?
Essentially they are the same;
NAG provides declare statements for the Fortran
Library and defines C types in VBA;
VB6 FL headers VB6 CL headers
C and VBA arrays start with 0, while Fortran arrays
with 1;
C arrays need transposing.
6
The IFAIL parameter
IFAIL in NAG Fortran Library serves two purposes:
On input it determines what action the Library
routine takes when an error is detected:
-1 (Soft Fail & Noisy Exit) – error message and continue;
0 (Hard Fail) – error message and stop;
1 (Soft Fail & Quiet Exit) – no error message and continue.
8
How to handle callbacks?
A callback is a piece of executable code that is passed
as an argument to other code.
D01BAF (d01bac) – calculates one-dimensional
Gaussian quadrature
Note:
Visual Basic AddressOf operator to handle callbacks
Argument Passing ByRef in Fortran and ByVal in C
9
Debugging
When writing your own code consider:
How the variables are declared
NAG doesn’t accept Variants
Integers are declared as Long
How arguments are passed (ByRef/ ByVal)
What the sizes and dimensions of arrays are
If the arrays are numbered from 0 or 1
If arrays need to be transposed
If IFAIL is set properly
10
How to pass arrays as arguments?
F03AFF (f03aff) – calculates the determinant of a real
matrix and performs LU factorization.
Note:
Reading the array from the worksheet (Range->Double)
Checking if the matrix is a square matrix
The result of the factorization is not shown. How can it be
shown?
11
Further applications of NAG Libraries
Option Pricing:
Option_Pricing_Example.xls
Portfolio Optimization:
Portfolio_Optimization_Example.xls
Wavelet Transforms, ODE’s, PDE’s, Numerical
Differentiation, Linear Algebra, Matrix Operations,
Statistical Analysis and many others...
12
Conclusions
13
References
Product documentation
http://www.nag.co.uk/support_documentation.asp
14
Questions?
www.nag.co.uk
support@nag.co.uk
Marcin.Krzysztofik@nag.co.uk
15