automatic function construction

Werner Kassens wkassens at libello.com
Tue Sep 1 13:29:02 CEST 2009


Hi,
i am new to scilab and would like to know how to automatically construct 
a function.
a small toy example:

function x=myfun(a),x=[1:length(a)]*a',endfunction          //a is a vector

suppose myfun is called often with an 'a' of the same length and suppose 
[1:length(a)]
would be a time intensive operation. i could calc that before the 
definition of myfun
for example like this:

function x=makeMyFun(lengthOfA)
    x=sci2exp( [1:lengthOfA],"x",0)+" * a'' "
    deff('x=newf(a)' ,x)
    x=newf
endfunction

and then e.g. do for a vector of length 3:

myfun=makeMyFun(3)

obviously makeMyFun looks somewhat stupid, as i translate the function 
first into
strings and then into a function. hence my question: is there a way to 
do that in
a more direct way?

i further noticed by doing a fun2string, that the 2. myfun is stored in 
a different
way - a kind of array (?) - than the 1. myfun. I guess that is less 
efficient?

Werner



More information about the users mailing list