Results 1 to 6 of 6

Math Help - Mathematica command question - matrix operator

  1. #1
    Newbie
    Joined
    Oct 2010
    Posts
    10

    Mathematica command question - matrix operator

    Hi.

    Is it possible to prepare a set of commands, which lists elements of any size matrix in such sequence like this:

    for 3x3 matrix:

    <br />
\left(<br />
\begin{array}{ccc}<br />
a & b & c \\<br />
d & e & f \\<br />
g & h & i<br />
\end{array}<br />
\right)<br />


    the sequence is: a, b, c, f, i, h, g, d, e;

    for matrix 4x4:

    <br />
\left(<br />
\begin{array}{cccc}<br />
a & b & c & d \\<br />
e & f & g & h \\<br />
i & j & k & l \\<br />
m & n & o & p<br />
\end{array}<br />
\right)<br />


    the sequence is: a, b, c, d, h, l, p, o, n, m, i, e, f, g, k, j,

    etc.

    So, the operator which forms the sequence, moves on matrix like a point drawing a spiral, independently of matrix’s size.


    Thanks for all your help.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    A Plied Mathematician
    Joined
    Jun 2010
    From
    CT, USA
    Posts
    6,318
    Thanks
    4
    Awards
    2
    I'm sure it is possible. Mathematica is a full-blown programming language with loops, if's, increments, etc. One command that will be helpful is the Dimensions command. For example,

    Dimensions[{{1, 2}, {3, 4}, {5, 6}}] returns

    {3,2}.


    You can access the first component of the result by indexing, which in Mathematica looks like this: [[i]]. So, for example,

    Dimensions[{{1, 2}, {3, 4}, {5, 6}}][[1]] returns

    3

    and

    Dimensions[{{1, 2}, {3, 4}, {5, 6}}][[2]] returns

    2.

    One more comment: indexing into a matrix looks like this:

    A[[1]][[4]], which gives you the 1,4 element of the matrix. For example,

    {{1, 2}, {3, 4}, {5, 6}}[[3]][[1]] returns

    5.

    I would set up some sort of a nested looping program to do what you are asking. Does this help?
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Oct 2010
    Posts
    10
    It will be great, if you send me any proposition of exact program to obtain results, which I have desired.

    Thanks in advance!
    Follow Math Help Forum on Facebook and Google+

  4. #4
    A Plied Mathematician
    Joined
    Jun 2010
    From
    CT, USA
    Posts
    6,318
    Thanks
    4
    Awards
    2
    No, that's not the way we work around here. The helpers here are volunteers, and those asking questions are expected to put in the main effort to solve their problems. We're here to help people get unstuck, not to exhibit complete solutions to the problems.

    So it's your turn to do something. What ideas do you have?
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Oct 2010
    Posts
    10
    So, if - for example - 3x3 matrix is

    A = {{a, b, c}, {d, e, f}, {g, h, i}},

    I may construct a list I've desired as

    X = {A[[1, 1]], A[[1, 2]], A[[1, 3]], A[[2, 3]], A[[3, 3]], A[[3, 2]],
    A[[3, 1]], A[[2, 1]], A[[2, 2]]}.

    Is it possible to use it, for example with 'Which' and/or 'While' commands, to generalize the procedure? I'm trying to do it...
    Follow Math Help Forum on Facebook and Google+

  6. #6
    A Plied Mathematician
    Joined
    Jun 2010
    From
    CT, USA
    Posts
    6,318
    Thanks
    4
    Awards
    2
    Excellent! Yes, your X list is precisely what you want. What you've got to do now is assign X programmatically. The While command would be very useful, I think. You could either append items to your X list, or you could pre-allocate the X list and use the ReplacePart command to replace the elements one at a time.

    Couple of ideas you might think about:

    1. Use East, South, West, and North as indicator directions for which direction you're traveling in the matrix.
    2. Use some sort of limit to tell you when to stop going in a particular direction.

    Where does all this get you?
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. [SOLVED] Left hand alignment in the matrix command and array command
    Posted in the LaTeX Help Forum
    Replies: 8
    Last Post: May 3rd 2011, 02:31 PM
  2. Mathematica, how to construct a tridiagonal matrix?
    Posted in the Math Software Forum
    Replies: 3
    Last Post: August 23rd 2010, 02:38 AM
  3. Replies: 0
    Last Post: December 3rd 2009, 08:40 AM
  4. Matrix Operator
    Posted in the Math Software Forum
    Replies: 1
    Last Post: October 27th 2008, 07:05 AM
  5. Can i do this with a matrix multiplication operator
    Posted in the Advanced Algebra Forum
    Replies: 1
    Last Post: August 20th 2005, 06:14 PM

Search Tags


/mathhelpforum @mathhelpforum