Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Creating matrix from another matrix using column position
Replies: 1   Last Post: Mar 28, 2013 4:05 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Bob Hanlon

Posts: 890
Registered: 10/29/11
Re: Creating matrix from another matrix using column position
Posted: Mar 28, 2013 4:05 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

To avoid naming conflicts with built-in symbol names, you should not
start symbol names with capital letters. For example, C is a built-in
symbol.

??C

C[i] is the default form for the i\[Null]\[Null]^th parameter or
constant generated in representing the results of various symbolic
computations. >>

Attributes[C]={NHoldAll,Protected}


Since you did not provide matrix a in a usable form (e.g., .cvs), it
must be regenerated:

a = ({Range[#, # + 5], Range[# + 9, # + 11],
Range[# + 6, # + 8], Range[# + 30, # + 35],
Range[# + 39, # + 41], Range[# + 36, # + 38]} //
Flatten) & /@ {1, 7, 13, 19, 31, 37, 43, 49,
61, 67, 73, 79, 91, 97, 103, 109};


The notional b array is

bArray = With[{m = Max[Dimensions[a]]},
Array[b, {m, m}]];


If I understand your algorithm, then to generate the c array

f[row_, col_] := Module[{
rp = (Last /@ Position[a, row] // Sort),
cp = (Last /@ Position[a, col] // Sort)},
If[Length[rp] == Length[cp],
Total[bArray[[##]] & @@@ Thread[{rp, cp}]], 0]]

c = With[{m = Max[a]},
Table[f[row, col], {row, m}, {col, m}]];

Looking at your test cases:

c[[49, 50]]

b[1, 2] + b[10, 11] + b[13, 14] + b[22, 23]

c[[1, 100]]

0


Bob Hanlon


On Sun, Mar 24, 2013 at 11:23 PM, anton siswo <masgandhul@gmail.com> wrote:
> Hello everyone here.....
>
> I have problem here, I have a matrix 16x24, lets call it matrix A. There is Matrix B 24x24 which depend on the reading row and column with values from Matrix A.
>
> Here are link for matrix A: https://docs.google.com/file/d/0B-dcMNCq0QF8OTdPMS1WRVNxb1k/edit?usp=sharing
>
> After that, I want to create matrix C, consist of matrix 150x150.
>
> The rule are below here:
>
> 1. Matrix C formed from matrix A.
> 2. Each row and column from matrix C are read the values from matrix A for each row, not the entire matrix. If there is no values from matrix A (based on the tables) from each row from matrix A, such as A[1,100] then the value in C[1,100] is 0. For examples, row and column in matrix C [49,50] are formed from matrix A, for 49 in [8,1];[7,10];[4,13];[3,22] and for 50 in [8,2];[7,11];[4,14];[3,23]. I'm already using Position command in mathematica.
> 3. After that, get the column value only from matrix C for 49 and 50. It should be like this, for 49-> 1,10,13,22 and for 50 -> 2,11,14,23.
> 4. When we already got the column value for 49 and 50, we are forming the value from point 3 into [1,2];[10,11];[13,14];[22,23]. this 4 new elements are taking the value from matrix B in B[1,2];B[10,11];B[13,14];B[22,23].
> 5. After finished taking the value in matrix B, we sum it. So it should be sum of values from B[1,2] + B[10,11] + B[13,14] + B[22,23].
> 6. When finished, we take the result in matrix C. So, it should be C[49,50] = value from B[1,2] + B[10,11] + B[13,14] + B[22,23].
> 7. It goes along the way for matrix C starting from [1,1] until [150,150] using the rules before.
>
> So, my question is how to implement it in mathematica? I'va been stuck for a month, because of this algorithm.
>
> Thank you very much and I do sorry for my bad grammar.
>





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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.