Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Re: Creating a matrix out of a submatrix in Maple and MMA
Replies: 0

 Count Dracula Posts: 2 Registered: 12/11/04
Re: Creating a matrix out of a submatrix in Maple and MMA
Posted: Jun 14, 1996 10:28 AM

In Message-ID: <4pp7go\$nqk@saluki-news.wham.siu.edu>
cribari@ysidro.econ.uiuc.edu writes:

> I have a matrix B of dimension p x p, and I need to create a new
> matrix A whose lower right q x q partition consists of the lower
> right q x q partition of B (q <= p) and the other elements are
> zero.

submatrix[A_?MatrixQ, q_Integer] :=
Module[{n = Length[A], m},
m = n - q;
Join[Array[0 &, {m, n}],
Apply[Join, Transpose[{Array[0 &, {q, m}], Map[Take[#, -q]&, Take[A, -q]]}], 1]
]]

In[3]:= mat = {{1, 2, 3, 4, 5}, {0, 1, 2, 3, 4}, {2, 3, 4, 5, 6}, {9, 10, 11, 12, 13}, {7, 8, 9, 10, 11}};

In[4]:= submatrix[mat, 2]

Out[4]= {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 12, 13}, {0, 0, 0, 10, 11}}

--
___________________________________________________________________________________
Levent Kitis lk3a@cars.mech.virginia.edu lk3a@kelvin.seas.virginia.edu
University of Virginia Department of Mechanical, Aerospace, and Nuclear Engineering