[Scilab-users] Matrix of function pointers?

Antoine Monmayrant antoine.monmayrant at laas.fr
Thu Nov 29 09:37:26 CET 2012


Hi Samuel,

Thanks for your fast and pertinent answer.
However, it does not work really well for what I try to do.
Indeed, I would like to use

f=[c,s]

as a normal function that is being able to call something like 
f(x)=[c(x),s(x)];
I assume that all the functions f,c and s share the same input arguments.
With your solution, it could work if I could call "L(:)(x)":

L=[cos sin];
L(1)(%pi)
  ans  =

   - 1.

L(2)(%pi)
  ans  =

     1.225D-16

//What I would like:

L(:)(%pi) //not implemented in scilab
  ans_I_am_dreaming_about =
     - 1.    1.225D-16

The ultimate goal here is to build something that I could manipulate 
like a matrix with a "*" operator that mimic what happens with a normal 
matrix:

L=[a b ; c d];
M=[e f; g h];
N=L*M==[a*e+b*g, a*f+b*h ; c*e+d*g, c*f+d*h];
and
N(x)==[a(x)*e(x)+b(x)*g(x), a(x)*f(x)+b(x)*h(x) ; c(x)*e(x)+d(x)*g(x), 
c(x)*f(x)+d(x)*h(x)];

I am not sure this can be done in scilab...

Cheers,

Antoine


On 28/11/2012 22:54, Samuel Gougeon wrote:
> Hello Antoine,
> Le 28/11/2012 21:44, Antoine Monmayrant a écrit :
>> .../...
>>
>> I tried to play with %fptr_c_fptr but without success.
> It could depend on the container you choose. The following works well:
> function  r=%fptr_c_fptr(f,g)
>      r  =  tlist(["fptrL"],  f,  g)
> endfunction
> // ----------------------------------
> function  r  =%fptrL_c_fptr(L,f)
>      r  =  tlist(["fptrL"],  L(2:$),  f)
> endfunction
>
> -->L = [ disp disp disp]
>   L  =
>         L(1)
>   fptrL
>         L(2)
>         L(3)
>         L(4)
>   
> or
> function  r=%fptr_c_fptr(f,g)
>      r  =  list(f,  g)
> endfunction
> // ----------------------------------
> function  r=%l_c_fptr(L,f)
>      r  =  list(L(:),  f)
> endfunction
>
> -->L = [ disp disp disp]
>   L  =
>         L(1)
>         L(2)
>         L(3)
>
> or
>
> function  r=%fptr_c_fptr(f,g)
>      c  =  cell(1,2)
>      c(1).entries  =  f
>      c(2).entries  =  g
>      r  =  tlist("fptrL",c)
> endfunction
> // ----------------------------------
> function  r=%fptrL_c_fptr(L,f)
>      c  =  L(2)
>      d  =  c.dims
>      d(2)  =  int32(d(2)*1.  +1)
>      setfield(2,  d,  c)
>      L2  =  getfield(3,c)  // entries
>      L2($+1)  =  f
>      setfield(3,L2,c)
>      r  =  tlist("fptrL",  L2)
> endfunction
> -->L = [ disp rand diag ];
>
> -->L(2)(1)("Hello boy")
>  Hello boy
>
> -->L(2)(2)(list(2,3))
>  ans  =
>     0.8497452    0.8782165    0.5608486
>     0.6857310    0.0683740    0.6623569
>
> -->L(2)(3)(1:4)
>  ans  =
>     1.    0.    0.    0.
>     0.    2.    0.    0.
>     0.    0.    3.    0.
>     0.    0.    0.    4.
>
>
> you may also prefer using a structure array instead of a cell
> as container. It should also work.
>
> Regards
> Samuel
>
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20121129/6740dc56/attachment.htm>


More information about the users mailing list