Inline functions including pi
David Bateman
adb014 at gmail.com
Fri Apr 25 20:46:02 CDT 2008
Nik Waldron wrote:
> Hi,
>
> I'm in the process of porting some Matlab scripts for my personal use, I
> am using Octave 3.0.1. I've had some problems with fplot, which I'll
> get to in a round about way. If I define a simple inline trig function
> including pi and attempt to evaluate it I get the following:
>
> octave:17> f=inline("sin(x*pi)")
> f =
>
> f(pi, x) = sin(x*pi)
>
> Octave has identified my function as having two variables (x and pi) as
> opposed to treating pi as a constant. Is there any way to convince the
> interpreter that pi is a constant?
This is (or was) the documented behavior of the inline function when I
implemented it... I'd suggest writing the above instead as
f = @(x) sin (x*pi);
as inline functions in matlab are deprecated in favor of anonymous
function like the above, probably exactly for this reason of confusion
of what are the arguments. The above will work both in Matlab and Octave.
D.
More information about the Help-octave
mailing list