# Thread: vector reordering w/ mathematica

1. ## 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]

2. 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.

3. 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}

4. 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]]]]