how to create list of functions
- Subject: how to create list of functions
- From: Stavros Macrakis
- Date: Sun, 20 Nov 2005 11:29:03 -0500
>
> I want to create a list of functions so that I can access them via an
> > index.
> > f(x):=x;
> > g(x):=x^2;
> > h(x):=2*x;
> >
> > a:[f(x),g(x),h(x)];
> >
> > a[2](5); expecting evaluation of g(x) returning 25
>
>
By the way, your list is not a list of functions, but a list of
expressions:
a => [x, x^2, 2*x]
If you really want to work with a list of expressions rather than functions,
you must specify what variable you're substituting, e.g.
subst(5,x,a[2]) => 25
or
lambda([x],a[2])(5) => 25
Otherwise, Maxima has no way of knowing what you mean. Consider
a: [ x*y, a*x, a*y]
Should a[2](5) be 5*x or a*5?
In the event, it is an error, because you can't apply an expression (a*x) to
a value, only a function.
-s