help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

compiling C++ and C functions for octave


From: Iago Mosqueira
Subject: compiling C++ and C functions for octave
Date: Mon, 25 Nov 2002 16:11:11 +0000

Hi,

I am trying to get the code below compiled with mkoctfile, and although
it compiles just fine, get running it from octave I get the following
error messageL

octave: relocation error: matern.oct: undefined symbol: matern

I am not an expert C or C++ programmer, but somebody here checked the
code and said it looked fine, and I don't get any error message from
gcc. Does anybody have any idea about what might be going on? Would this
function work with vectors as input?

Many thanks,


Iago


-------------------------

#define MATHLIB_STANDALONE
#include <Rmath.h>
#include <math.h>
#include <octave/oct.h>

extern "C" float matern (float&, float&, int&);

DEFUN_DLD (matern, args, ,
  "Matern variogram function")
{

        octave_value_list retval;

        /* Number of arguments*/
        int nargs = args.length ();
        
        /* Error checking*/
        if (nargs!=3){
                usage("matern (x, phi, kappa)");
                return retval;
        }

        float x = (args(0).double_value());
        float phi = (args(1).double_value());
        int kappa = (args(2).int_value());

        retval = matern (x, phi, kappa);


  return retval;
}


float matern(float x, float phi, int kappa)
{
        /*Returns the Matern function for x, phi and kappa.*/

        /* Variables */
        float ans, cte;
        float uphi=x/phi;

        /* Matern */

        if (uphi==0) return 1;
        else{
        if (kappa==0.5) 
                ans = exp(-uphi);
        else {
                cte = R_pow(2, (-(kappa-1)))/gammafn(kappa); 
                ans = cte * R_pow(uphi, kappa) * bessel_k(uphi,kappa,1); 
        }
        }

        return ans;
}



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]