Previously I post on how to call GSL function, now it’s time for ARPACK. In octave, when you run interactively, you just need to run “eigs” for various matrix function. So Octave has provided some bindings to call ARPACK functions. So following the same steps as calling GSL function:

download arpack-1.0.6.tar.gz.

unzip the file and type “./configure” and “make”, but don’t type “make install”. Under folder “src” you can find two files “eigs.cc” and “eigs-base.cc”. If you look inside “eigs.cc”, this file will include “eigs-base.cc” in the beginning.

Comment or delete the DLD_FUNC lines and replace with an ordinary function name

`octave_value_list eigs(octave_value_list args,unsigned int nargout)`

I also created a header file

`#include "eigs.h"`

where it only contains the prototype of the functions and some #define directives

`#ifndef EIGS`

#define EIGS

#define HAVE_ARPACK

octave_value_list eigs(octave_value_list args,unsigned int nargout);

#endif

we need to define “HAVE_ARPACK”, otherwise, the function will not run. Nothing to be done for eigs-base.cc, except removing the warning due to NaN.

To compile your C++ code, you will need to use “-larpack” during linking. Otherwise it will give error.

In your main program, you can call “eigs” function as follows:

` octave_value_list fargs;`

fargs.append(M);

fargs.append(octave_value(4));

fargs.append(octave_value("sm"));

octave_value_list retval=eigs(fargs,2);

Matrix V(retval(0).matrix_value());

Matrix D(retval(1).matrix_value());

where M is the matrix of one input argument. Type “help eigs” in your octave prompt if you are not familiar with the syntax (of course you need to do pkg install arpack-1.0.6.tar.gz inside Octave, if you have not done so)

Now, about the warning. After I successfuly called the function. I kept on getting this warning:

`warning: eigs: 'A - sigma*B' is singular, indicating sigma is exactly`

warning: an eigenvalue. Convergence is not guaranteed

After some debugging, it turns out the octave_NaN variable was not set properly. A simple way to overcome this is to initialize octave_NaN again. You can call this line

`octave_NaN=NAN;`

inside eigs-base.cc functions. This should solve the problem.

Filed under: Uncategorized | Tagged: c++, octave |

## Leave a Reply