Results 1 to 4 of 4

Math Help - vector reordering w/ mathematica

  1. #1
    Newbie
    Joined
    Sep 2008
    Posts
    9

    vector reordering w/ mathematica

    I have an object with 10 points. I have created a vector:

    DOF={0,1,2,3,4,5,6,7,8,9}

    Further in my notebook I have solved to find:
    DOFS={0,4,8} - these numbers will be different

    I would now like to reorder these so that DOFS comes first and then the rest follow in numerical order.

    realigned={0,4,8,1,2,3,5,6,7,9}

    right now I have:

    Code:
    realigned = Table[0, {i, 10}, {j, 1}];
    count = 1
    For[i = 1, i <= 3, i++,
      	realigned[[count]] = DOFS[[i]];
      	count = count + 1];
    For[i = 1, i <= 10, i++,
             If[realigned[i] == DOFS[[i]],
             Continue[]]; realigned[[count]] = i; count = count + 1]
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Super Member
    Joined
    Aug 2008
    Posts
    903
    Code:
    In[55]:= tab1 = {0, 4, 8};
    tab2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    Join[tab1, Select[tab2, Not[MemberQ[tab1, #]] &]]
    
    Out[57]= {0, 4, 8, 1, 2, 3, 5, 6, 7, 9}
    First select from tab2, those which are not in tab1, then just join tab1 to that list. The # is a place-holder and the & designates it as a pure function: go through the list tab2, and insert each element in that list into the place-holder inside MemberQ and compare it to all the members of tab1. Finish evaluating the expression.
    Last edited by shawsend; October 1st 2008 at 02:14 PM.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Sep 2008
    Posts
    9
    OK, now I have:

    Ks=10x10 matrix (ordered 1-10)

    and

    New={1,5,9,2,3,4,6,7,8,10} my vector or new order

    I would now like to create a new "reduced" matrix that is 7x7 using all but the first three i's and j's so that I would end up w/ a 7x7 matrix ordered

    {2,3,4,6,7,8,10}
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Super Member
    Joined
    Aug 2008
    Posts
    903
    Not sure what you want. Try this. Can you interpret the functional programming: sequence = ({#1} & ) /@ Take[new, -7]?
    It's very cryptic I know. Only way is practice: Establish the pure function {{#}&. Now apply (/@ is shorthand for Apply) this function to each element in the list formed by taking the last seven elements from new. That gives {{2},{3},{4},{6},{7},{8},{10}}. The format needed for Extract.

    Code:
    new = {1, 5, 9, 2, 3, 4, 6, 7, 8, 10}; 
    sequence = ({#1} & ) /@ Take[new, -7]; 
    n = 0; 
    oldmatrix = Table[n++, {i, 1, 10}, 
        {j, 1, 10}]; 
    MatrixForm[oldmatrix]
    firststep = Extract[oldmatrix, sequence]
    secondstep = MatrixForm[firststep[[All,
        Take[new, -7]]]]
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Help about Mathematica
    Posted in the Math Software Forum
    Replies: 2
    Last Post: June 1st 2010, 11:46 AM
  2. mathematica
    Posted in the Math Software Forum
    Replies: 0
    Last Post: October 27th 2009, 01:03 PM
  3. LCM/GCD With Mathematica
    Posted in the Math Software Forum
    Replies: 3
    Last Post: January 7th 2009, 06:49 AM
  4. Replies: 5
    Last Post: March 22nd 2008, 05:28 PM
  5. vector differentiation by looping in Mathematica
    Posted in the Math Software Forum
    Replies: 0
    Last Post: January 22nd 2008, 06:42 PM

Search Tags


/mathhelpforum @mathhelpforum