Re: VectorToMatrix
- To: mathgroup at smc.vnet.net
- Subject: [mg4359] Re: VectorToMatrix
- From: Count Dracula <lk3a at kelvin.seas.virginia.edu>
- Date: Thu, 11 Jul 1996 01:02:33 -0400
- Organization: University of Virginia
- Sender: owner-wri-mathgroup at wolfram.com
In Message-ID: <4qqn5d$49m at dragonfly.wolfram.com> Robert Pratt <rpratt at 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 at cars.mech.virginia.edu lk3a at kelvin.seas.virginia.edu University of Virginia Department of Mechanical, Aerospace, and Nuclear Engineering ==== [MESSAGE SEPARATOR] ====