Re: [Scilab-users] Get back the name of a function given as argument

2015-10-13 Thread Pierre Vuillemin

Hi Samuel,

Thank you for the answer. I have finally came up with this routine :

function funName = sopi_retrieveFunName(f)
varList = who_user(%f);
for i = 2:size(varList,1) // "f" is the local copy of the function 
and is the first one in the varList, it must be discarded

varName = varList(i);
execstr("var = "+varName);
if var == f then
funName = varName;
break;
end
end
endfunction

It retrieves the name of the function given as argument by comparing it 
to the user's variables. It (very) far from being elegant, but it seems 
to work.


Will there be a better way to achieve that with Scilab 6 ?

Pierre


Le 12.10.2015 21:02, Samuel Gougeon a écrit :

Hi Pierre,

Le 12/10/2015 16:46, Pierre Vuillemin a écrit :

Hi all,

I am building some optimisation tools, and in this context, I was 
wondering if it was possible to get back the name of a function given 
as argument of another function.


More specifically, consider the function 'fun' defined as

deff('[f,g] = fun(x)','f = x^2;g = 2*x');

and an optimisation routine "minimize" which first argument is a 
function.


Is there a way to get back the name of the function "fun" when calling 
"minimize(fun)" ?


I am afraid that, with 5.5.2,  you have to use something like
minimize("thefun") instead, with

function argout = minimize(fun,...)
execstr("fun="+fun);
   ...
endfunction

Samuel

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] Get back the name of a function given as argument

2015-10-13 Thread Pierre Vuillemin

My bad, I've just realised that

- this routine will actually give the name of the last copy of the 
function (in case of multiple imbricated function calls),


- besides, a simpler solution consists in using the name of the local 
copy of the function.


deff('y = fun(x)','y = x^2');
deff('y = f(x)','y = x');
deff('minimize(f)','disp(evstr(''f(2)''))');

minimize(f)   // displays 2
minimize(fun) // displays 4


Le 13.10.2015 08:44, Pierre Vuillemin a écrit :

Hi Samuel,

Thank you for the answer. I have finally came up with this routine :

function funName = sopi_retrieveFunName(f)
varList = who_user(%f);
for i = 2:size(varList,1) // "f" is the local copy of the function
and is the first one in the varList, it must be discarded
varName = varList(i);
execstr("var = "+varName);
if var == f then
funName = varName;
break;
end
end
endfunction

It retrieves the name of the function given as argument by comparing
it to the user's variables. It (very) far from being elegant, but it
seems to work.

Will there be a better way to achieve that with Scilab 6 ?

Pierre


Le 12.10.2015 21:02, Samuel Gougeon a écrit :

Hi Pierre,

Le 12/10/2015 16:46, Pierre Vuillemin a écrit :

Hi all,

I am building some optimisation tools, and in this context, I was 
wondering if it was possible to get back the name of a function given 
as argument of another function.


More specifically, consider the function 'fun' defined as

deff('[f,g] = fun(x)','f = x^2;g = 2*x');

and an optimisation routine "minimize" which first argument is a 
function.


Is there a way to get back the name of the function "fun" when 
calling "minimize(fun)" ?


I am afraid that, with 5.5.2,  you have to use something like
minimize("thefun") instead, with

function argout = minimize(fun,...)
execstr("fun="+fun);
   ...
endfunction

Samuel

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


[Scilab-users] Get back the name of a function given as argument

2015-10-12 Thread Pierre Vuillemin

Hi all,

I am building some optimisation tools, and in this context, I was 
wondering if it was possible to get back the name of a function given as 
argument of another function.


More specifically, consider the function 'fun' defined as

deff('[f,g] = fun(x)','f = x^2;g = 2*x');

and an optimisation routine "minimize" which first argument is a 
function.


Is there a way to get back the name of the function "fun" when calling 
"minimize(fun)" ?


I would like to get back its name to wrap it inside another function 
which includes calls towards numerical derivatives, if needed.


Best regards,

Pierre Vuillemin










___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] Get back the name of a function given as argument

2015-10-12 Thread Samuel Gougeon

Hi Pierre,

Le 12/10/2015 16:46, Pierre Vuillemin a écrit :

Hi all,

I am building some optimisation tools, and in this context, I was 
wondering if it was possible to get back the name of a function given 
as argument of another function.


More specifically, consider the function 'fun' defined as

deff('[f,g] = fun(x)','f = x^2;g = 2*x');

and an optimisation routine "minimize" which first argument is a 
function.


Is there a way to get back the name of the function "fun" when calling 
"minimize(fun)" ?


I am afraid that, with 5.5.2,  you have to use something like 
minimize("thefun") instead, with


function argout = minimize(fun,...)
execstr("fun="+fun);
   ...
endfunction

Samuel

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users