|
|
Re: VectorToMatrix
Posted:
Jul 8, 1996 1:55 AM
|
|
In Message-ID: <4qqn5d$49m@dragonfly.wolfram.com> Robert Pratt <rpratt@math.unc.edu> wrote:
> I want to define a function VectorToMatrix[list_, n_] that behaves as > follows:
> VectorToMatrix[{a,b,c,d,e,f,g,h,i,j}, 4]//MatrixForm
> 0 a b c d > 0 0 e f g > 0 0 0 h i > 0 0 0 0 j
Here's one solution:
vectomat[v_List, n_Integer] := Flatten /@ Transpose[{(Table[0, {#1}] & ) /@ Range[n], (Take[v, #1] & ) /@ FoldList[Plus, {1, n}, Transpose[{Range[n, 2, -1], Range[n - 1, 1, -1]}]]}]
In[3]:= vec = {a, b, c, d, e, f, g, h, i, j, k, l, m, n, p};
In[4]:= MatrixForm[vectomat[vec, 5]]
Out[4]//MatrixForm= 0 a b c d e
0 0 f g h i
0 0 0 j k l
0 0 0 0 m n
0 0 0 0 0 p
-- ___________________________________________________________________________________ Levent Kitis lk3a@cars.mech.virginia.edu lk3a@kelvin.seas.virginia.edu University of Virginia Department of Mechanical, Aerospace, and Nuclear Engineering
|
|