Services & Resources / Wolfram Forums
MathGroup Archive
*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
  • Subject: [mg69511] Re: fast replace for matrix minor
  • From: "astanoff" <astanoff at>
  • Date: Thu, 14 Sep 2006 06:56:30 -0400 (EDT)
  • References: <ee8hcp$j7g$>

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

Hi Chris,

This is my way to do that kind of block replace
without any Do, For or While :

In[1]:=replaceBlock[oldMatrix_?MatrixQ, newBlock_?MatrixQ,
      {startRow_Integer, startColumn_Integer}]:=
    Module[{endRow, endColumn, rep},
      {endRow, endColumn} = {startRow, startColumn}+
      rep[i_ /; startRow <= i <= endRow,
          j_ /; startColumn <= j <= endColumn]:=
        newBlock[[i-startRow+1, j-startColumn+1]];
      rep[i_,j_] := oldMatrix[[i,j]];
      Array[rep, Dimensions[oldMatrix]]

Example :



hth [you to improve your timing...]


  • Prev by Date: Integate[] warning shows only first time, but not the second time?
  • Next by Date: RE: question on changing 'type' of numbers
  • Previous by thread: Re: fast replace for matrix minor
  • Next by thread: Differential equation