help-octave
[Top][All Lists]

 From: lash Subject: Re: Dynamically Linked Functions. Date: Mon, 15 Feb 1999 13:03:43 -0600 (CST)

```Ohh!  I think I understand what is happening now.  The
function is being compiled as c++ code, and in the case
of pow(x(0),2) it looks at the two arguments and sees a
double? and an int.  libm normally supplies a pow function
that takes a double and a double and returns a double.

When C++ does its name mangling, in the first case it will
look for a function with a name like pow__d_di  or something
like that to indicate the return type and the argument types.
The standard math library only supplies a version of pow that
would be pow__d_dd.

When Matteo introduced the doubles, it caused everything to work
ok.  You should be able to get the same results with

dx(0) = ... *(double)pow((double)x(0),(double)2)

or it might be sufficient just to write:

dx(0) = ... *pow(x(0),2.0)

if x(0) is already double.  I think 2.0 would default to double,
but it might be a float.

Bill

>
>
>
> Hi Sven and Heber,
>
> I met the same problem with oregonator,
> and, following Heber tip, achieved to let
> it work cutting the pow function:
>
> dx(0) = ... *pow(x(0),2) );  // doesn't work
>
> dx(0) = ... * x(0) * x(0) ); // ok!
>
> But I realised (and I do not know why)
> that there is another solution, that allows
> you to call the 'pow' function:
>
>     double tmp, tmp2, tmp3;
>
>       tmp3 = 2.;
>       tmp2 = x(0);
>       tmp = pow(tmp2,tmp3);
>
>       dx(0) = ... * tmp );  // OK!
>
> I couldn't obtain the same error (the one in
> the first line of code '...pow(x(0),2)' in a
> stand-alone C program.
> I'm running RedHat 5.1, egcs-1.0.2-12, octave-2.1.9
>
> bye,
> Matteo
>
>
>
>
> ----------------------
>       Matteo Bettella
>
>       School of Mechanical Engineering
>       Automotive Engineering Group
>       Cranfield University
>       Cranfield
>       Bedford MK43 0AL
>
>       Tel.: (00)44-(0)1234-754652
>               (00)44-(0)7801-711311