MathGroup Archive 2006

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

Search the Archive

RE: Initialize a matrix in mathematica

  • To: mathgroup at
  • Subject: [mg66787] RE: [mg66742] Initialize a matrix in mathematica
  • From: "Erickson Paul-CPTP18" <Paul.Erickson at>
  • Date: Tue, 30 May 2006 05:48:44 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

It seems 

nvid = 5; Table[ i^i, {i, nvid}]

Should do what I think you want. Check out Table, Array, etc. in the
help files.

There are those that would prefer

Array[ #^# &, nvid]

Do to the explicit use of Array and lack of named iterator, but IMO
whichever is clear to the user is probably the preferred.


-----Original Message-----
From: ashesh [mailto:ashesh.cb at] 
To: mathgroup at
Subject: [mg66787] [mg66742] Initialize a matrix in mathematica

Hi All,

Have programmed in another system until now and am trying to shift to
Mathematica and facing some diffciulties

I would like to create a matrix, say a[ndiv] and would like to initilize
all the value to i^2 (or any other value). The size of the matrix is not

The code I tried to use is:

ndiv = 5;
a = {};
For[i=1, i<=ndiv, i++,
a[[i]] = i*i;

This is producing the following error:
partw: Part 1 of {} does not exist and so on.

I understand that I am not creating a matrix of size 1*ndiv for the data
to be fed it.

So I tried using Table as follows:

a = Table[0,{1},{ndiv}] followed by the above For loop (when I wanted to
initialize the matrix with say i*i;

Hope some one can help me in doing the above operation


  • Prev by Date: Re: Exporting Graphics to .eps
  • Next by Date: Re: Re: Prefix function syntax f @ x
  • Previous by thread: RE: Initialize a matrix in mathematica
  • Next by thread: Behavior of ReplaceAll with Computed Results from a Conditional Test