[Date Index]
[Thread Index]
[Author Index]
Re: Variables names
*To*: mathgroup at smc.vnet.net
*Subject*: [mg15031] Re: [mg15002] Variables names
*From*: Andrzej Kozlowski <andrzej at tuins.ac.jp>
*Date*: Wed, 9 Dec 1998 04:12:17 -0500
*Sender*: owner-wri-mathgroup at wolfram.com
On Sat, Dec 5, 1998, Kim Allemand <kim.allemand at epfl.ch> wrote:
>Hi,
>I have a square matrix Q of dimension N and would like to generate the
>quadratic function $\sum_{i,j}q_{ij}x_i x_j$. The problem is how to say
>to Mathamatica that the variables names are x1, x2, etc. Is it possible
>to generate variables names in an automatic way? A possibility would be
>to generate manually a vector NN={x1, x2, x3, ....} of dimension N and
>then to pick NN[[i]] for the ith variable name, but imagine when
>N=1000... !!
>Thanks, Kim
>
Here is an improved verion of my previous program, with much better
notation. Is this what you had in mind or have I failed to understand
your point?
In[1]:=
variablelist[x_,n_]:=
Map[ToExpression,
Map[StringJoin,Map[ToString,Transpose[{Table[x,{n}],Range[n]}],{2}]]]
quadratic[q_,x_,n_]:=
Flatten[Outer[Times,variablelist[x,n],variablelist[x,n]]].Flatten[
Array[q,{n,n}]]
In[3]:=
quadratic[q,x,10]
Out[3]=
2
x1 q[1, 1] + x1 x2 q[1, 2] + x1 x3 q[1, 3] +
x1 x4 q[1, 4] + x1 x5 q[1, 5] + x1 x6 q[1, 6] +
x1 x7 q[1, 7] + x1 x8 q[1, 8] + x1 x9 q[1, 9] +
2
x1 x10 q[1, 10] + x1 x2 q[2, 1] + x2 q[2, 2] +
x2 x3 q[2, 3] + x2 x4 q[2, 4] + x2 x5 q[2, 5] +
x2 x6 q[2, 6] + x2 x7 q[2, 7] + x2 x8 q[2, 8] +
x2 x9 q[2, 9] + x10 x2 q[2, 10] + x1 x3 q[3, 1] +
2
x2 x3 q[3, 2] + x3 q[3, 3] + x3 x4 q[3, 4] +
x3 x5 q[3, 5] + x3 x6 q[3, 6] + x3 x7 q[3, 7] +
x3 x8 q[3, 8] + x3 x9 q[3, 9] + x10 x3 q[3, 10] +
x1 x4 q[4, 1] + x2 x4 q[4, 2] + x3 x4 q[4, 3] +
2
x4 q[4, 4] + x4 x5 q[4, 5] + x4 x6 q[4, 6] +
x4 x7 q[4, 7] + x4 x8 q[4, 8] + x4 x9 q[4, 9] +
x10 x4 q[4, 10] + x1 x5 q[5, 1] + x2 x5 q[5, 2] +
2
x3 x5 q[5, 3] + x4 x5 q[5, 4] + x5 q[5, 5] +
x5 x6 q[5, 6] + x5 x7 q[5, 7] + x5 x8 q[5, 8] +
x5 x9 q[5, 9] + x10 x5 q[5, 10] + x1 x6 q[6, 1] +
x2 x6 q[6, 2] + x3 x6 q[6, 3] + x4 x6 q[6, 4] +
2
x5 x6 q[6, 5] + x6 q[6, 6] + x6 x7 q[6, 7] +
x6 x8 q[6, 8] + x6 x9 q[6, 9] + x10 x6 q[6, 10] +
x1 x7 q[7, 1] + x2 x7 q[7, 2] + x3 x7 q[7, 3] +
x4 x7 q[7, 4] + x5 x7 q[7, 5] + x6 x7 q[7, 6] +
2
x7 q[7, 7] + x7 x8 q[7, 8] + x7 x9 q[7, 9] +
x10 x7 q[7, 10] + x1 x8 q[8, 1] + x2 x8 q[8, 2] +
x3 x8 q[8, 3] + x4 x8 q[8, 4] + x5 x8 q[8, 5] +
2
x6 x8 q[8, 6] + x7 x8 q[8, 7] + x8 q[8, 8] +
x8 x9 q[8, 9] + x10 x8 q[8, 10] + x1 x9 q[9, 1] +
x2 x9 q[9, 2] + x3 x9 q[9, 3] + x4 x9 q[9, 4] +
x5 x9 q[9, 5] + x6 x9 q[9, 6] + x7 x9 q[9, 7] +
2
x8 x9 q[9, 8] + x9 q[9, 9] + x10 x9 q[9, 10] +
x1 x10 q[10, 1] + x10 x2 q[10, 2] + x10 x3 q[10, 3] +
x10 x4 q[10, 4] + x10 x5 q[10, 5] + x10 x6 q[10, 6] +
x10 x7 q[10, 7] + x10 x8 q[10, 8] + x10 x9 q[10, 9] +
2
x10 q[10, 10]
Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp/
Prev by Date:
**Re: Variables names**
Next by Date:
**Re: Mathematica Ouput: subscripts and superscripts**
Previous by thread:
**Re: Variables names**
Next by thread:
**Re: Variables names**
| |