# [Maxima] In Need of Help In Defining a List of n variables

Robert Dodier robert.dodier at gmail.com
Tue Oct 7 22:58:49 CDT 2008

On Tue, Oct 7, 2008 at 11:06 AM, Azhar Hasham

> I'm a new user of Maxima and am currently trying to figure out how to
> produce a list of n variables (x1,... xn) where n is general. I'm aware of
> the function makelist, but for this I need to define an integer value for n
> which I don't want to do.

Maxima in some respects treats subscripted variables like ordinary,
unsubscripted ones, so to some extent you can just write x[1], x[2],
x[i], x[n] or whatever. (Maxima probably should be more consistent
about subscripted variables but let's leave it alone for now.)

> Ultimately I want to define the following function on these n variables:
>
> g(x):=sum(((n*x[i])/sum(x[j],j,1,n)-1)^2,i,1,n)
>
> and then find the taylor expansion of this function in the variables
> x1,..xn.
>
> Is it possible to do this without actually specifying a value for n?

Well, I think so, if you just want compute a definite number of terms.
(I don't know how to compute the n'th derivative of g where n is indefinite.)
Here's what I get. I haven't checked this result.

(%i1) display2d : false\$
(%i2) g(x) := sum (((n*x[i])/sum(x[j], j, 1, n) - 1)^2, i, 1, n)\$
(%i3) foo : g(u);
(%o3) 'sum((u[i]*n/'sum(u[j],j,1,n)-1)^2,i,1,n)
(%i4) declare (sum, linear);
(%o4) done
(%i5) expand (foo);
(%o5) ('sum(u[i]^2,i,1,n))*n^2/('sum(u[j],j,1,n))^2
-2*('sum(u[i],i,1,n))*n/'sum(u[j],j,1,n)+n
(%i6) niceindices (%);
(%o6) ('sum(u[i]^2,i,1,n))*n^2/('sum(u[i],i,1,n))^2-n
(%i7) foo1 : diff (%, u[i]);
(%o7) 2*n^2/'sum(u[i],i,1,n)-2*('sum(u[i]^2,i,1,n))*n^3/('sum(u[i],i,1,n))^3
(%i8) foo2 : diff (foo1, u[i]);
(%o8) 6*('sum(u[i]^2,i,1,n))*n^4/('sum(u[i],i,1,n))^4
-6*n^3/('sum(u[i],i,1,n))^2
(%i9) foo3 : diff (foo2, u[i]);
(%o9) 24*n^4/('sum(u[i],i,1,n))^3-24*('sum(u[i]^2,i,1,n))*n^5
/('sum(u[i],i,1,n))^5

What makes this tractable by Maxima is that there aren't any indices
other than a literal i, for example, I made j go away by renaming it to i
(via niceindices), and there isn't anything like i + 1 or n - i.
It's probably possible to get Maxima to do the right thing for those cases
but it would be more work.

Note that by default sum does not distribute over minus.
declare(sum, linear) makes that happen.

Hope this helps,

Robert Dodier