03: Create an array of values

Create arrays of numerical values

  • create the array of square roots of n for n=1,2,...,9
  • create an array of 15 random real values uniformly distributed between 0 and 10
  • create a 5×3 array of integer chosen randomly between 1 and 100

Mathematica:

a1=Table[ Sqrt[n], ]   (exact)
a1=Table[ N[Sqrt[n]], ]   (numerical)

a2 = Table[10Random[],15]

a3 = Table[Random[Integer,],5,3]

Matlab:

a1 = sqrt(1:9)

a2 = 10 * rand(size(1:15))

a3 = round(100*rand(5,3) + 0.5)

Maple:

seq(sqrt(n),n=1..9);
seq(evalf(sqrt(n)),n=1..9);

with(stats);
seq( random[uniform](1)*10, n=1..15 );

g := rand(1..100);
[seq([seq(g(),n=1..5)],n=1..5)];

IDL:

a1 = sqrt( findgen(9)+1 )

a2 = 10 * randomu(seed, 15)

a3 = fix(100*randomu(seed,5,5) + 1.5)