Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*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 2006

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

Search the Archive

Re: Dynamic iterators in Do loop

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66299] Re: Dynamic iterators in Do loop
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Mon, 8 May 2006 00:46:46 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 5/6/06 at 11:50 PM, iwillfail at gmail.com (sai) wrote:

>I have an (n,n) matrix. I want to define an (m,m) matrix [m<n] whose
>elements are defined from the (n,n) matrix. The value of n and m
>changes from problem to problem. How can i do this in mathematica?

There are a number of ways to accomplish what you want. Which is best would depend on precisely what you want to do. For example, the upper m X m sub-matrix can be extracted from the n X n matrix (a) as follows:

Take[Take[#,m]&/@a,m]

Once the sub-matrix is obtained Map can be used to Map any arbitrary function to each element of the matrix.

For example,

In[30]:=
n=4;
m=3;
a=Table[10 i+j,{i,n},{j,n}];
b=Take[Take[#,m]&/@a,m];
Map[Total[IntegerDigits@#]&,b,{2}]

Out[34]=
{{2, 3, 4}, {3, 4, 5}, {4, 5, 6}}
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: General--Differential equation problem..
  • Next by Date: Re: Mathematica 4.1 on ThinkPAD T40 - Exception ntdll.dll - any advice on how to fix?
  • Previous by thread: Re: Dynamic iterators in Do loop
  • Next by thread: Re: Dynamic iterators in Do loop