more on inline

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

more on inline

Teemu Ikonen
Hi,

I tried function valued parameters with Matlab R13, and found that Octave is
not fully compatible, although it does the right thing:

octave:16> ff = inline("f(x)", "f", "x")
ff =

f(f, x) = f(x)

octave:17> ff(@sin, 1)
ans = 0.84147

Matlab:
>> ff = inline('f(x)', 'f', 'x')
ff =
     Inline function:
     ff(f,x) = f(x)
>> ff(@sin, 1)
ans =
    @sin
>> version
ans =
6.5.0.180913a (R13)
             
I'm not sure if this still the behaviour of R14, but this might be one case
where bug for bug compatibility is not a good idea.

Teemu


Reply | Threaded
Open this post in threaded view
|

more on inline

John W. Eaton-6
On 16-Sep-2004, Teemu Ikonen <[hidden email]> wrote:

| Matlab:
| >> ff = inline('f(x)', 'f', 'x')
| ff =
|      Inline function:
|      ff(f,x) = f(x)
| >> ff(@sin, 1)
| ans =
|     @sin
| >> version
| ans =
| 6.5.0.180913a (R13)

I think this has changed.  In R13, function handles were an array
type, so indexing them picked an element from the array.  In R14, they
made them a scalar type only, so indexing them performs a function
call.  So in the above, you are selecting the first element of the
function handle array stored in f.  Try

  ff (@sin, 2)

and see if you don't get a different result (range error on the
index).

With the new behavior, I would expect Matlab to be compatible with the
current Octave behavior and call the sin function through the function
handle with the argument 1.

jwe