Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: fast replace for matrix minor

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69527] Re: fast replace for matrix minor
  • From: "Ray Koopman" <koopman at sfu.ca>
  • Date: Thu, 14 Sep 2006 06:57:24 -0400 (EDT)
  • References: <ee8hcp$j7g$1@smc.vnet.net>

Christopher Arthur wrote:
> Is there a quick way to replace a small minor block in a large matrix?
> Using ReplacePart in a Do loop seems to be very inefficient with
> respect to timing
>
> Chris Arthur

In[1]:= a = Table[10i+j,{i,6},{j,9}]

Out[1]= {{11, 12, 13, 14, 15, 16, 17, 18, 19},
         {21, 22, 23, 24, 25, 26, 27, 28, 29},
         {31, 32, 33, 34, 35, 36, 37, 38, 39},
         {41, 42, 43, 44, 45, 46, 47, 48, 49},
         {51, 52, 53, 54, 55, 56, 57, 58, 59},
         {61, 62, 63, 64, 65, 66, 67, 68, 69}}

To replace the values in rows 4..5, columns 3..6:

In[2]:= b = Table[-10i-j, {i,4,5},{j,3,6}]

Out[2]= {{-43,-44,-45,-46},
         {-53,-54,-55,-56}}

In[3]:= ReplacePart[a, b,
                    Flatten[Table[{i,j},{i,4,5},{j,3,6}],1],
                    Flatten[Table[{i,j},{i,1,2},{j,1,4}],1]]

Out[3]= {{11, 12, 13, 14, 15, 16, 17, 18, 19},
         {21, 22, 23, 24, 25, 26, 27, 28, 29},
         {31, 32, 33, 34, 35, 36, 37, 38, 39},
         {41, 42,-43,-44,-45,-46, 47, 48, 49},
         {51, 52,-53,-54,-55,-56, 57, 58, 59},
         {61, 62, 63, 64, 65, 66, 67, 68, 69}}


  • Prev by Date: partials of Sum[x[i]^2, {i,1,n}] (e.g.)
  • Next by Date: Re: Derivative of a function with multiple variables
  • Previous by thread: Re: fast replace for matrix minor
  • Next by thread: Re: fast replace for matrix minor