Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Messages: [ Previous | Next ]
 Count Dracula Posts: 2 Registered: 12/11/04
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

Date Subject Author
6/26/96 Robert Pratt
6/28/96 Demetri Mouratis
6/28/96 Dr. T. L. Marchioro II
7/8/96 Paul A. Rubin
7/8/96 Count Dracula
7/8/96 Nicholas Santucci
7/8/96 Paul Abbott