[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: another question : arrays of functions ???
From: |
A. S. Hodel |
Subject: |
Re: another question : arrays of functions ??? |
Date: |
Thu, 13 Jun 1996 14:01:56 -0500 (CDT) |
The blessing and the curse of Octave and Matlab is that the basic data
type is a matrix, a 2x2 array of numbers. John has already expanded that
somewhat by allowing for structures, and has also included a mode for
dealing with matrices that are string arrays (less convenient than
Matlab perhaps, but it does the job).
A kludgy way to do what you're discussing here would be to create an
array of strings containing function names, and then use eval to
evaluate each one independently, i.e.,
funclist(1,:) = "bessel";
funclist(2,1:5) = "gamma";
...
for ii-1:n
x(i) = eval([setstr(funclist(i,:),'(x)']);
endfor
Matlab would require a similar approach, of course without the setstr
function call, which is unique to Octave.
Notice that the name of x must be in a string.
On Thu, 13 Jun 1996, Kay Hamacher wrote:
> Date: Thu, 13 Jun 1996 19:38:56 +0200 (MET DST)
> From: Kay Hamacher <address@hidden>
> To: address@hidden
> Subject: another question : arrays of functions ???
>
> Hello.
>
> There is another question which comes up by thinking
> of a solution for an exercise :
>
> Is there a way to declare arrays of functions ?
>
> I think of the possibilities of Pascal :
> Var a : Array[1..20] Of Function(x:Real) : Real;
>
> and then do callings like
> for i := 1 to 20 Do b := b + a[i](3);
>
> Kay
>
> ----------------------------------------------------------------------------
> Kay Hamacher InterNet : address@hidden
> WWW http://www.wupper.de/sites/lucie/index.html
>
> WINDOWS : From the people who brought you edlin
>
A S Hodel Dept Elect Eng 200 Broun Hall, Auburn Univ., AL 36849
(334) 844-1854/fax-1809 http://www.eng.auburn.edu/~scotte