From: Etienne G. <et...@is...> - 2002-08-10 17:27:51
Attachments:
inline.m
|
Hello again, On Sat, Aug 10, 2002 at 01:32:42PM +0000, Steffan Berridge wrote: #=20 # Hi, #=20 # I have just started using Octave, having used Matlab for a # while. In Matlab I have often used inline functions, they # are very convenient for example when passing a function as # an argument. #=20 # For example, the following is a function returning the # square of the argument: #=20 # fun =3D inline('x^2','x'); Try the attached m-file, called inline.m. Is that, or something alike, worthy of octave-forge? Cheers, Etienne =20 # One can then pass this function as an argument to another # function: #=20 # x =3D foo(fun,...); #=20 # So my question is, is there an equivalent construction in # Octave? If not, what is the best way to pass functions as # arguments? #=20 # Thanks, # Steffan #=20 #=20 #=20 #=20 # ------------------------------------------------------------- # Octave is freely available under the terms of the GNU GPL. #=20 # 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 # ------------------------------------------------------------- #=20 #=20 #=20 #=20 # =00=00=00=00=00=00=00=00=00 --=20 Etienne Grossmann ------ http://www.isr.ist.utl.pt/~etienne |
From: Etienne G. <et...@is...> - 2002-08-10 17:31:21
Attachments:
inline.m
|
Sorry, there was a part missing from the first attached func. Try the following. Etienne On Sat, Aug 10, 2002 at 01:32:42PM +0000, Steffan Berridge wrote: # # Hi, # # I have just started using Octave, having used Matlab for a # while. In Matlab I have often used inline functions, they # are very convenient for example when passing a function as # an argument. # # For example, the following is a function returning the # square of the argument: # # fun = inline('x^2','x'); # # One can then pass this function as an argument to another # function: # # x = foo(fun,...); # # So my question is, is there an equivalent construction in # Octave? If not, what is the best way to pass functions as # arguments? # # Thanks, # Steffan -- Etienne Grossmann ------ http://www.isr.ist.utl.pt/~etienne |
From: Paul K. <pki...@ja...> - 2002-08-10 20:04:42
|
Sure. Add it to octave forge. I simplified the while loop a bit, and let you use a default parameter of "x". I wouldn't go much beyond this in terms of compatibility --- too many assumptions required about what makes a variable and what order the variables should go in. Maybe inline(expr,n) as shorthand for inline(expr,"x","P1","P2",...,"Pn") is useful. Paul Kienzle pki...@us... On Sat, Aug 10, 2002 at 06:37:46PM +0100, Etienne Grossmann wrote: > > Sorry, there was a part missing from the first attached func. Try > the following. > > Etienne > > On Sat, Aug 10, 2002 at 01:32:42PM +0000, Steffan Berridge wrote: > # > # Hi, > # > # I have just started using Octave, having used Matlab for a > # while. In Matlab I have often used inline functions, they > # are very convenient for example when passing a function as > # an argument. > # > # For example, the following is a function returning the > # square of the argument: > # > # fun = inline('x^2','x'); > # > # One can then pass this function as an argument to another > # function: > # > # x = foo(fun,...); > # > # So my question is, is there an equivalent construction in > # Octave? If not, what is the best way to pass functions as > # arguments? > # > # Thanks, > # Steffan > -- > Etienne Grossmann ------ http://www.isr.ist.utl.pt/~etienne ## [fname,fcode] = inline (str,arg1,...) - Define a function from a string ## ## INPUT : ----------- ## str : string : String defining the result of the function ## argN : string(s) : Names of the arguments of the function ## ## OUTPUT : ---------- ## fname : string : Name of the new function, which can e.g. be called w/ ## feval() ## fcode : string : The code of the function ## ## EXAMPLE : --------- ## ## fn = inline ("x.^2 + 1","x"); ## feval (fn, 6) ## ans = 36 ## function [fname,fcode] = inline (str,varargin) ## Choose a name (naive way : won't work zillions of times) while 1 fname = sprintf ("inline_func_%06i",floor (rand()*1e6)); if exist (fname), break; end end ## construct arg list if nargin == 1 argstr = "x"; else argstr = sprintf ("%s,",all_va_args); argstr = argstr(1:length(argstr)-1); end fcode = sprintf (["function r = %s (%s)\n",\ " r = ",str,";\n",\ "endfunction;"],\ fname, argstr); eval (fcode); endfunction |
From: Etienne G. <et...@is...> - 2002-08-11 15:05:04
|
Hello, On Sat, Aug 10, 2002 at 04:04:24PM -0400, Paul Kienzle wrote: # Sure. Add it to octave forge. I simplified the while loop a bit, and let Good, but "if ! exist (fname), break; endif" is better. # you use a default parameter of "x". I wouldn't go much beyond this in # terms of compatibility --- too many assumptions required about what makes a # variable and what order the variables should go in. Maybe inline(expr,n) as # shorthand for inline(expr,"x","P1","P2",...,"Pn") is useful. Or "x1", "x2", ... ? Does Matlab do such a thing? I would keep it as it is. I'll check in your version w/ "x" as default but won't do more refinements. Cheers, Etienne # Paul Kienzle # pki...@us... # # On Sat, Aug 10, 2002 at 06:37:46PM +0100, Etienne Grossmann wrote: # > # > Sorry, there was a part missing from the first attached func. Try # > the following. # > # > Etienne # > # > On Sat, Aug 10, 2002 at 01:32:42PM +0000, Steffan Berridge wrote: # > # # > # Hi, # > # # > # I have just started using Octave, having used Matlab for a # > # while. In Matlab I have often used inline functions, they # > # are very convenient for example when passing a function as # > # an argument. # > # # > # For example, the following is a function returning the # > # square of the argument: # > # # > # fun = inline('x^2','x'); # > # # > # One can then pass this function as an argument to another # > # function: # > # # > # x = foo(fun,...); # > # # > # So my question is, is there an equivalent construction in # > # Octave? If not, what is the best way to pass functions as # > # arguments? # > # # > # Thanks, # > # Steffan # > -- # > Etienne Grossmann ------ http://www.isr.ist.utl.pt/~etienne # # ## [fname,fcode] = inline (str,arg1,...) - Define a function from a string # ## # ## INPUT : ----------- # ## str : string : String defining the result of the function # ## argN : string(s) : Names of the arguments of the function # ## # ## OUTPUT : ---------- # ## fname : string : Name of the new function, which can e.g. be called w/ # ## feval() # ## fcode : string : The code of the function # ## # ## EXAMPLE : --------- # ## # ## fn = inline ("x.^2 + 1","x"); # ## feval (fn, 6) # ## ans = 36 # ## # function [fname,fcode] = inline (str,varargin) # # ## Choose a name (naive way : won't work zillions of times) # while 1 # fname = sprintf ("inline_func_%06i",floor (rand()*1e6)); # if exist (fname), break; end # end # # ## construct arg list # if nargin == 1 # argstr = "x"; # else # argstr = sprintf ("%s,",all_va_args); # argstr = argstr(1:length(argstr)-1); # end # # fcode = sprintf (["function r = %s (%s)\n",\ # " r = ",str,";\n",\ # "endfunction;"],\ # fname, argstr); # eval (fcode); # endfunction # # # -- Etienne Grossmann ------ http://www.isr.ist.utl.pt/~etienne |
From: Julius S. <jo...@cc...> - 2008-12-06 22:47:45
|
<html> <body> <font size=3>Hi All,<br><br> In trying to 'make all' in the latest octave-forge repo working copy on Mac OS X (Macbook Pro), I got a hang at<br><br> Making html comms.html<br> [indefinite hang]<br><br> Drilling down I found that /usr/bin/texi2html was hanging. I happened to have another one in /opt/local/bin (presumably installed via 'port install texi2html' or 'port install tetex' or the like), and that fixed it. I made the following change in Makeconf:<br><br> #TEXI2HTML = /usr/bin/texi2html -split_chapter -number<br> TEXI2HTML = /opt/local/bin/texi2html -split_chapter -number<br><br> </font>and now the build is proceeding.<br><br> Julius<br><br> <br> <x-sigsep><p></x-sigsep> <font size=4>"Anybody who knows all about nothing knows everything" -- Leonard Susskind<br> </font></body> </html> |