Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: VectorToMatrix
Replies: 6   Last Post: Jul 8, 1996 2:19 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Count Dracula

Posts: 2
Registered: 12/11/04
Re: VectorToMatrix
Posted: Jul 8, 1996 1:55 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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







Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.