MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Multiply a constant to a matrix column

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16356] Re: Multiply a constant to a matrix column
  • From: dreiss at !SPAMscientificarts.com (David Reiss)
  • Date: Thu, 11 Mar 1999 02:16:36 -0500
  • Organization: EarthLink Network, Inc.
  • References: <7bo0gg$dop@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <7bo0gg$dop at smc.vnet.net>, heahn at nanum.kaeri.re.kr (Hyo ahn) wrote:

> Hi,
> 
> I would like to multiply a constant number to a certain column of an existing
> matrix in Mathematica and I am having a hard time.
> 
> First, I have a 1000 x 3 matrix A.  There is no command that allow me to
> multiply a constant number to a specific column (let say I want to multiply
> 100 to the second column), so I extract three columns
> separately using
> 
> A1 = A[Range[1,1000],Range[1,1]];
> A2 = A[Range[1,1000],Range[2,2]];
> A3 = A[Range[1,1000],Range[3,3]];
> 
> Then I multiply a constant to a extracted
> column which is a vector now.   So I did
> 
> A2b = 100 A2;
> 
> Then I recombined the columns as
> 
> A4 = ColumnJoin[A1,A2b,A3]
> 
> but I found out that ColumnJoin command does not worked the way I expected
> it to be.
> 
> Could anyone know a simple solution to this problem?
> 
> Thanks.
> 
> Hyo Ahn
> KAERI



One way to do this is to use MapAt along with Transpose.  
First define a matrix:

In[1]:=
mat={{a,b,c},{d,e,f},{g,h,i}}

Out[1]=
{{a,b,c},{d,e,f},{g,h,i}}


If I want to multiply the constant "x" on the second row I would use


In[2]:=
MapAt[Times[x,#]&,mat,2]


Out[2]=
{{a,b,c},{d x,e x,f x},{g,h,i}}


To get at the columns of the matrix I first transpose 
it and them transpose it back.  Thus this multiplies 
the second column by  "x":


In[3]:=
Transpose[MapAt[Times[x,#]&,Transpose[mat],2]]

Out[3]=
{{a,b x,c},{d,e x,f},{g,h x,i}}


--David

-- 


   
----------------------------------------
 
Scientific Arts:
Creative Services and Consultation 
for the Applied and Pure Sciences
 
  http://www.scientificarts.com

David Reiss 
Email: dreiss at !SPAMscientificarts.com 

----------------------------------------
 


Remove the !SPAM to send email


  • Prev by Date: Re: a tricky List manipulation problem
  • Next by Date: Re: Multiply a constant to a matrix column
  • Previous by thread: Re: Multiply a constant to a matrix column
  • Next by thread: Producing ASCII File