Transforming matrices

• To: mathgroup at smc.vnet.net
• Subject: [mg29665] Transforming matrices
• From: loopm at yahoo.com (Michael Loop)
• Date: Mon, 2 Jul 2001 02:20:26 -0400 (EDT)
• Organization: The Math Forum
• Sender: owner-wri-mathgroup at wolfram.com

```I am a relatively new user of Mathematica, and I am having some
trouble transforming a matrix.  I would be appreciative of any advice.
The problem is as follows.

Given a randomly formed matrix of form:

0 0 1 2 2 2 0 0 0 0 0 0 1 2 0 1 2 2 2 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Each digit represents a different state, and therefore each digits
position must be preserved.  I need to convert this matrix into a
matrix of rates instead.  The zeros will be converted into constant
rates dependent on their position, and the rate will continue until a
1 is reached.  Both 1 and 2 represent a rate of 0.  So given a vector
of rates:

40 38, 37, 36, 33, 32, 31, 30, 27, 23, 22, 21, 20, 16, 14, 13, 12, 10,
9, 6

I need to convert the first randomly generated matrix to look like:

40 40  0  0  0  0 32 32 32 32 32 32  0  0 16  0  0  0  0  9
40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40
40 40  0  0  0  0 32 32 32 32 32 32 32 32 32 32 32 32 32 32

Besides the fact that the rate must stay constant until a 1 is
reached, the other subtlety of my problem is that when a rate starts
over after a 1 or 2, the new rate must begin in the position of the
next zero, but the rate must come from the position of the last 1 or
2.  I can convert a matrix of this form on an individual basis using
the Position and Table commands, but cannot find an efficient way of
converting the matrix on a large scale.  The matrix I actually need to
convert is 240*1000, so if anyone can think of an efficient way of
doing this I would be grateful for your input.  Thank you.

Micahel Loop
Minneapolis, MN

```

• Prev by Date: Re: .m file to C or Fortran source code
• Next by Date: Re: Problems with TeX and EPS output (v3.0, mac)
• Previous by thread: Re: .m file to C or Fortran source code
• Next by thread: Re: Transforming matrices