Copying a small quadratic matrix into a bigger quadratic matrix




On Thu, 8 Apr 2010, Eberhard Franz wrote:

< Hi everybody,
< 
< I just want to copy e.g. a 4x4 matrix into e.g. 6x6 at a certain location. I
< found that this could be done via two nested loops:
< 
< for i:3 thru 6 step 1 do for j:3 thru 6 step 1 do Kge2_ex[i,j]:Kge2[i-2,j-2];
< 
< Is there any smarter way?
 
genmatrix with a lambda function can do the trick,

genmatrix(lambda([i,j], if i<5 and j<5 then A[i,j] else 0), 6,6);

or some variation on this.

Leo

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.