# inline functions in Matlab R14

11 messages
Open this post in threaded view
|

## inline functions in Matlab R14

 Can someone who has Matlab R14 say what it does in the following cases?   inline ('p_1+1')   inline ('p+q')   inline ('abc+xyz') Thanks, jwe
Open this post in threaded view
|

## Re: inline functions in Matlab R14

 According to John W. Eaton <[hidden email]> (on 09/22/04): > Can someone who has Matlab R14 say what it does in the following > cases? > >   inline ('p_1+1') > >   inline ('p+q') > >   inline ('abc+xyz') Could I also suggest the case    inline ('Abc+xyZ') as the documentation is seems to imply special treatment for upper and lower case characters... D. -- David Bateman                                [hidden email] Motorola CRM                                 +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax) 91193 Gif-Sur-Yvette FRANCE The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary
Open this post in threaded view
|

## RE: inline functions in Matlab R14

 In reply to this post by John W. Eaton-6 >> inline('p_1+1') ans =      Inline function:      ans(p_1) = p_1+1 >> inline('p+q') ans =      Inline function:      ans(p,q) = p+q >> inline('abc+xyz') ans =      Inline function:      ans(abc,xyz) = abc+xyz -----Original Message----- From: John W. Eaton [mailto:[hidden email]] Sent: Wednesday, September 22, 2004 1:30 PM To: octave maintainers mailing list Subject: inline functions in Matlab R14 Can someone who has Matlab R14 say what it does in the following cases?   inline ('p_1+1')   inline ('p+q')   inline ('abc+xyz') Thanks, jwe
Open this post in threaded view
|

## RE: inline functions in Matlab R14

 In reply to this post by John W. Eaton-6 Still seems to get it right.  Matlab indicates they're using a function called "symvar" to figure out what are the variables. >> inline('Abc+xyZ') ans =      Inline function:      ans(Abc,xyZ) = Abc+xyZ -----Original Message----- From: David Bateman [mailto:[hidden email]] Sent: Wednesday, September 22, 2004 12:36 PM To: John W. Eaton Cc: octave maintainers mailing list Subject: Re: inline functions in Matlab R14 According to John W. Eaton <[hidden email]> (on 09/22/04): > Can someone who has Matlab R14 say what it does in the following > cases? > >   inline ('p_1+1') > >   inline ('p+q') > >   inline ('abc+xyz') Could I also suggest the case    inline ('Abc+xyZ') as the documentation is seems to imply special treatment for upper and lower case characters... D. -- David Bateman                                [hidden email] Motorola CRM                                 +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax) 91193 Gif-Sur-Yvette FRANCE The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary
Open this post in threaded view
|

## Re: inline functions in Matlab R14

 In reply to this post by John W. Eaton-6 John W. Eaton wrote: > Can someone who has Matlab R14 say what it does in the following > cases? > >   inline ('p_1+1') > >   inline ('p+q') > >   inline ('abc+xyz') > > Thanks, > > jwe > Here is what I get:(seems meaningful): I removed some empty lines: 'p_1+1' is a function of one variable, others of two variables (complains with 1 input). -------------------------------  >> version ans = 7.0.0.19901 (R14)  >> inline ('p_1+1') ans =       Inline function:       ans(p_1) = p_1+1  >>   inline ('p+q') ans =       Inline function:       ans(p,q) = p+q  >>   inline ('abc+xyz') ans =       Inline function:       ans(abc,xyz) = abc+xyz % and testing:  >> g = inline ('p_1+1') g =       Inline function:       g(p_1) = p_1+1  >> g(1) ans =       2  >> g(2) ans =       3  >> k = inline ('p+q') k =       Inline function:       k(p,q) = p+q  >> k(1,1), k(pi,exp(1)) ans =       2 ans =      5.8599  >> h  = inline ('abc+xyz') h =       Inline function:       h(abc,xyz) = abc+xyz  >> h(1,1) ans =       2  >> h(1,2) ans =       3  >> l = inline ('Abc+xyZ') l =       Inline function:       l(Abc,xyZ) = Abc+xyZ  >> l(1,pi) ans =      4.1416 % and for vector inputs:  >> g([1,1]) ans =       2     2  >> l([1,1],2) ans =       3     3
Open this post in threaded view
|

## Re: inline functions in Matlab R14

 In reply to this post by David Bateman-3 Here's the output I get:                               < M A T L A B >                   Copyright 1984-2004 The MathWorks, Inc.                          Version 7.0.0.19901 (R14)                                May 06, 2004   To get started, type one of these: helpwin, helpdesk, or demo.   For product information, visit www.mathworks.com.  >>  >> inline ('p_1+1') ans =      Inline function:      ans(p_1) = p_1+1  >> inline ('p+q') ans =      Inline function:      ans(p,q) = p+q  >> inline ('abc+xyz') ans =      Inline function:      ans(abc,xyz) = abc+xyz  >> inline ('Abc+xyZ') ans =      Inline function:      ans(Abc,xyZ) = Abc+xyZ David Bateman wrote: >According to John W. Eaton <[hidden email]> (on 09/22/04): >   > >>Can someone who has Matlab R14 say what it does in the following >>cases? >> >>  inline ('p_1+1') >> >>  inline ('p+q') >> >>  inline ('abc+xyz') >>     >> > >Could I also suggest the case > > >   inline ('Abc+xyZ') > >as the documentation is seems to imply special treatment for upper and >lower case characters... > >D. > >   >
Open this post in threaded view
|

## RE: inline functions in Matlab R14

 In reply to this post by HALL, BENJAMIN PW On 22-Sep-2004, Hall, Benjamin <[hidden email]> wrote: | Still seems to get it right. For some value of "right".  The observed behavior does not seem to match my reading of the docs. jwe
Open this post in threaded view
|

## Re: inline functions in Matlab R14

 In reply to this post by Quentin Spencer Even worse, what do inline('sin (x)') and inline('y (x)') give.. I suspect they give ans =      Inline function:      f(x) = sin (x) and ans =      Inline function:      f(x) = y (x) since how can you tell if "sin" and "y" are functions or not. Even if they aren't when you define the inline function they might be afterwards... Another ambiguity is inline('x+i'), inline('x+j'), inline('x+I'), inline('x+J') the first two should have i and j ignored. But matlab doesn't define I and J. Also what about the octave built in constants "e" and "E"? Should they also be ignored... I also noticed that matlab sorts the arguments in ascii order. So that inline('a+Y') -> f =      Inline function:      f(Y,a) = a+Y Grrr, this is a case where matlabs documentation doesn't even closely resemble what they actually do. The attached patch tries to do something similar to the matlab behaviour. I ignore the octave builtin constants "I", "J", "e" and "E"... John, its up to you if you also want to drop these as potential inline function arguments... D. 2004-09-23 David Bateman <[hidden email]>         * ov-fcn-inline.cc (Finline): Do what the other brand actually         does, rather than what they say they do. According to Quentin Spencer <[hidden email]> (on 09/22/04): > Here's the output I get: > >                              < M A T L A B > >                  Copyright 1984-2004 The MathWorks, Inc. >                         Version 7.0.0.19901 (R14) >                               May 06, 2004 > > >  To get started, type one of these: helpwin, helpdesk, or demo. >  For product information, visit www.mathworks.com. > > >> > >> inline ('p_1+1') > ans = >     Inline function: >     ans(p_1) = p_1+1 > >> inline ('p+q') > ans = >     Inline function: >     ans(p,q) = p+q > >> inline ('abc+xyz') > ans = >     Inline function: >     ans(abc,xyz) = abc+xyz > >> inline ('Abc+xyZ') > ans = >     Inline function: >     ans(Abc,xyZ) = Abc+xyZ > > > > > David Bateman wrote: > > >According to John W. Eaton <[hidden email]> (on 09/22/04): > > > > > >>Can someone who has Matlab R14 say what it does in the following > >>cases? > >> > >> inline ('p_1+1') > >> > >> inline ('p+q') > >> > >> inline ('abc+xyz') > >>   > >> > > > >Could I also suggest the case > > > > > >  inline ('Abc+xyZ') > > > >as the documentation is seems to imply special treatment for upper and > >lower case characters... > > > >D. > > > > > > -- David Bateman                                [hidden email] Motorola CRM                                 +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax) 91193 Gif-Sur-Yvette FRANCE The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary patch.sort20040923 (3K) Download Attachment
Open this post in threaded view
|

## Re: inline functions in Matlab R14

 On 23-Sep-2004, David Bateman <[hidden email]> wrote: | Even worse, what do | | inline('sin (x)') | | and | | inline('y (x)') | | give.. I suspect they give | | ans = | |      Inline function: |      f(x) = sin (x) | | and | | ans = | |      Inline function: |      f(x) = y (x) | | since how can you tell if "sin" and "y" are functions or not. Even if they | aren't when you define the inline function they might be afterwards... In Matlab, that is not possible because all functions are either built-in or defined in a .m file somewhere in your path.  Although I suppose you could modify the path later and a new function would be available.  In that case, I don't think it would go back and alter the affected inline functions, but if you used the same inline again, this time with the external function(s) available, I would expect it to change the meaning.  Once again, bad design.  Is it surprising? | Another ambiguity is | | inline('x+i'), inline('x+j'), inline('x+I'), inline('x+J') | | the first two should have i and j ignored. But matlab doesn't define | I and J. Also what about the octave built in constants "e" and "E"? | Should they also be ignored... Ugh. | The attached patch tries to do something similar to the matlab behaviour. | I ignore the octave builtin constants "I", "J", "e" and "E"... John, its | up to you if you also want to drop these as potential inline function | arguments... OK, I applied the patch (sorry I missed it yesterday).  Unfortunately, it does not really recognize functions correctly.  What if you do   inline ('array_variable(2)') (i.e., you are defining a function to extract elements from an array).  The current version of inline does this:   octave:1> inline ('array_variable (2)')   ans =   f(array) = array_variable (2)   octave:2> inline ('arrayvar (2)')   ans =   f() = arrayvar (2) In both cases, Matlab apparently does   f(x) = arrayvar (2) which also seems wrong.  I have no function called arrayvar defined, so it should be recognized as an argument to the function.  So even Matlab is not actually looking at what functions are available.  It is just using some lame half-parsing rules.  I don't think that can possibly work in all cases.  BTW, it appears that your code will recognize variable names inside character strings. Also, what about functions that do not expect arguments.  In Matlab, you are not allowed to write   eye () to call a function, so you must write the name alone.  In that case, you might write a wrapper function as inline like this:   inline ('eye + 3') but again, the current version of inline recognizes 'eye" as a variable here.  Oh well, Matlab seems to do the same. So the only real "bugs" that I see in the current code are:   * It doesn't recognize "_" in symbol names.  Matlab R13 does not     recognize leading underscores, but does recognize embedded     underscores.  Perhaps that is a bug?   * It doesn't handle things like       inline ('foo (''bar baz'', x, y, z)')     correctly -- the only args should be x, y, and z.   * It doesn't use "x" as the default variable name, passed when no     other variables are recognized (why it does this, I have no idea). Finally, fixing these things is not all that important to me.  I'd file this in the category of bug-for-bug compatibility.  I think the only safe thing to do is always specify the arguments explicitly.   jwe