The Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » sci.math.* » sci.math

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

Advanced Search

Back to Topic List Back to Topic List  
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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply



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







Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2017. All Rights Reserved.