# [Maxima] defining functions of s variables

Stavros Macrakis macrakis at alum.mit.edu
Tue Jan 8 10:38:43 CST 2008

```On Jan 8, 2008 10:25 AM, Barton Willis <willisb at unk.edu> wrote:

> (%i1) sum_it_up([x]) := apply("+",x)\$ ...
>

If you want a function that has one or more arguments, try:
> (the [x] argument must be last and there can only be one []
> argument)

Depending on your requirements, you may want to use Barton's approach of
defining a function which is called with s arguments, e.g. f(x1,x2,x3) using
the f([l]):=... syntax, or a function which is called with one argument, a
vector, e.g. f([x1,x2,x3]), using simply f(l):=....  My general preference
would be for the latter, because it means you can conveniently treat the
argument vector as an object, e.g.

f( argvec . matrix)
length(argvec) => ...

Maxima does also support apply(f, argvec), but if you are mostly
manipulating vectors, this is not as convenient.

The apply("+", ...) trick works nicely for n-ary functions like "+" and the
like, but you might also want to consider using sum(x[i],i,1,length(x)) and
rreduce(f, x) == f(x[1],f(x[2],...)) (also lreduce -- all of which Barton
wrote, by the way).

(%i10) f([x]) := apply("*", map("^",x, makelist(k,k,1,length(x))));
>

Or

product( x[k]^k, k, 1, length(x))

As for

f(x) := x[1]^1 * x[2]^2 * x[3]^3
diff(f(x), x[1], 1);

This works for me.  By the way, if your x's are strictly formal, it might be
easier to manipulate *expressions* than functions, e.g.

f:  product(x[k]^k, i,1,3);

diff(f,x[2]) => 2*x[1]*x[2]*x[3]^3

Let us know if you have other issues.

-s
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.math.utexas.edu/pipermail/maxima/attachments/20080108/2aec8bf3/attachment.htm
```