[Date Index]
[Thread Index]
[Author Index]
Re: matrix manipulation using transformations
*To*: mathgroup at yoda.physics.unc.edu
*Subject*: Re: matrix manipulation using transformations
*From*: Jeffrey Edwin Thoma <jet3v at helga11.acc.virginia.edu>
*Date*: Fri, 4 Jun 1993 21:01:00 GMT
Michael Carter wanted a simple way to divide each row in a matrix by its
last element using transformation rules. There are two ways to do this
that I can think of.
1). If you know that the matrix will always be the same size, eg
3x3.
m /. m[[{1,2,3}]] -> m[[{1,2,3}]] /
{m[[1,3]],m[[2,3]],m[[3,3]]}
This works, but it seems kind of kludgey.
2). A more general method is:
m /. m -> m/Last[Transpose[m]]
I have included an example of method 2 (which works with any size vector
or matrix) below. I use 3x3 in the example since it prints up smaller.
-----------------
Mathematica 2.0 for IBM RISC System 6000
Copyright 1988-91 Wolfram Research, Inc.
In[1]:= SymMat[imax_, jmax_] := Array[a, {imax, jmax}]
In[2]:= RndMat[imax_, jmax_] := Table[Random[] + 0.0001, {i, 1, imax},
{k, 1, jmax}]
In[3]:= mSym = SymMat[3,3]
Out[3]= {{a[1, 1], a[1, 2], a[1, 3]}, {a[2, 1], a[2, 2], a[2, 3]}, {a[3,
1], a[3, 2], a[3, 3]}}
In[4]:= mNum = RndMat[3,3]
Out[4]= {{0.480837, 0.18627, 0.656986}, {0.628739, 0.732096, 0.625209},
{0.209607, 0.471707, 0.862245}}
In[5]:= mNum /. mNum -> mNum /Last[Transpose[mNum]]
Out[5]= {{0.731884, 0.283523, 1.}, {1.00565, 1.17096, 1.}, {0.243094,
0.547068, 1.}}
In[6]:= mSym /. mSym -> mSym /Last[Transpose[mSym]]
a[1, 1] a[1, 2] a[2, 1] a[2, 2] a[3, 1] a[3,
2]
Out[6]= {{-------, -------, 1}, {-------, -------, 1}, {-------,
-------, 1}}
a[1, 3] a[1, 3] a[2, 3] a[2, 3] a[3, 3] a[3,
3]
-------------------
I hope this is what you want (If you really wanted a way to divide the
kth row by its last element, then I think you would be better off using
functions instead of transformation rules).
Good Luck,
Jeff
Prev by Date:
**Re: 2D Integration**
Next by Date:
**Re: citing Mma**
Previous by thread:
**Aborts**
Next by thread:
**Re: Object Oriented...(really Math. Journal)**
| |