MathGroup Archive 2006

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

Search the Archive

Re: fast replace for matrix minor

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