MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Variables names

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15092] Re: [mg15048] Re: [mg15002] Variables names
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Sat, 12 Dec 1998 03:58:57 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

On Wed, Dec 9, 1998, Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
wrote:

>Hi Kim,
>
>the best way is to use x[i] instead of x1, x2, ...
>
>You can still generate the names with
>
>ToExpression["x"<>ToString[i]]
>
>Hope that helps
>  Jens
>
>Kim Allemand 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
>


I think it may be interesting to point out the two approaches are not
really equivalent.  The difference between them, i.e. between x1, x2,
x3 etc. and x[1],x[2], x[3] is that in the first case we have genuine
variable names, in the second values of a function x. This means that
in the first case pattern matching on the indices will have no effect
on the "variables" , while in the second case it will. Compare the
following two examples:

In[1]:=
x1^2+x2^2/.(2->3)
Out[1]=
  3     3
x1  + x2
In[2]:=
x[1]^2+x[2]^2/.(2->3)
Out[2]=
    3       3
x[1]  + x[3]

I can imagine cases where one or the other behaviour is more desirable,
so I do not think one can definitely say that one of these aproaches is
superior to the other.


Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp/
http://eri2.tuins.ac.jp/



  • Prev by Date: Re: Monte Carlo simulations on a Mac??
  • Next by Date: Block and Module
  • Previous by thread: Re: Variables names
  • Next by thread: error from MathLink, plotting results from a c++ simulation