Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1993
*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 1993

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

Search the Archive

Re: Matrix Operations in Mma

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: Re: Matrix Operations in Mma
  • From: colinr at sue.econ.su.oz.au (Colin Rose)
  • Date: Wed, 29 Sep 93 1:13:12 EET

      Martin Rickli writes:
>>    How can I assign a matrix to a part of another matrix?
>>    eg. Replace the lower right 2x2 matrix in a 3x3 Identity matrix 
>>    by say {{a,b},{c,d}} to get the result   { {1,0,0},
>>                                               {0,a,b},
>>                                               {0,c,d} } 


     One way of doing this would be to define a function  Hi[A, S, {x, y}]
that substitutes the matrix S into matrix A at element {x, y}. For instance:

Hi[A_, S_, {x_, y_}] := (k=A;  Do[k=ReplacePart[k, S[[i,j]], {i+x-1,j+y-1}], 
                         {i, Dimensions[S][[1]]}, {j, Dimensions[S][[2]]}]; k)

Then, for your example:

In[]:=      M = IdentityMatrix[3];    
            R = { {a, b}, {c, d} };
            Hi[M, R, {2, 2}]  

Out[]=      1   0   0
            0   a   b
            0   c   d


Here is another example:

In[]:=      M = IdentityMatrix[5];    
            R = { {a, b, c}, {d, e, f} };
            Hi[M, R, {3, 2}]    

Out[]=      1   0   0   0   0
            0   1   0   0   0
            0   a   b   c   0
            0   d   e   f   0
            0   0   0   0   1

Regards

Colin

Colin Rose
Dept. of Economics
University of Sydney
colinr at extro.ucc.su.oz.au
*************************






  • Prev by Date: chemical kinetics
  • Next by Date: Serious problem with DelaunayTriangulation package?
  • Previous by thread: the problem
  • Next by thread: Serious problem with DelaunayTriangulation package?