Student Support Forum: 'Help with creating matrix from another matrix' topicStudent Support Forum > General > "Help with creating matrix from another matrix"

 < Previous Comment | Next Comment > Help | Reply To Comment | Reply To Topic
 Author Comment/Response Bill Simpson 04/12/13 00:35am In Response To 'Re: Re: Re: Re: Re: Re: Re: Re: Help with creat...'---------I will only compute two rows here to show. In[2]:= c = Table[ xp = Map[Last, Position[a[[y]], x]]; yp = Map[Last, Position[a[[y]], y]]; m = Min[Length[xp], Length[yp]]; xp = Take[xp, m]; yp = Take[yp, m]; If[xp=={} || yp=={} || Length[xp]!=Length[yp], 0, Plus@@Map[b[[Sequence@@#]]&, Transpose[{yp, xp}]]], {y, 2}, {x, 150}] Out[2]= {{b[[1, 1]], b[[1, 2]], b[[1, 3]], b[[1, 4]], b[[1, 5]], b[[1, 6]], b[[1, 10]], b[[1, 11]], b[[1, 12]], b[[1, 7]], b[[1, 8]], b[[1, 9]], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, b[[1, 13]], b[[1, 14]], b[[1, 15]], b[[1, 16]], b[[1, 17]], b[[1, 18]], b[[1, 22]], b[[1, 23]], b[[1, 24]], b[[1, 19]], b[[1, 20]], b[[1, 21]], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} To compute the first row of matrix c I will look for 1 and x in the first row of matrix a. There is a 1 in the first row of matrix a and so I can compute matrix c[1,x]. Is the first row of matrix c correct now? To compute the second row of matrix c I will look for 2 and x in the second row of matrix a. There is no 2 in the second row of matrix a and so I cannot compute c[2,x] for matrix c and the result is all zero for the second row of matrix c. This is in error. I will guess a change. To compute the second row of matrix c I will look for 2 and x in the first and second row of matrix a. In[3]:= c = Table[ xp = Map[Last, Position[Take[a, y], x]]; yp = Map[Last, Position[Take[a, y], y]]; m = Min[Length[xp], Length[yp]]; xp = Take[xp, m]; yp = Take[yp, m]; If[xp=={} || yp=={} || Length[xp]!=Length[yp], 0, Plus@@Map[b[[Sequence@@#]]&, Transpose[{yp, xp}]]], {y, 2}, {x, 150}] Out[3]= {{b[[1, 1]], b[[1, 2]], b[[1, 3]], b[[1, 4]], b[[1, 5]], b[[1, 6]], b[[1, 10]], b[[1, 11]], b[[1, 12]], b[[1, 7]], b[[1, 8]], b[[1, 9]], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, b[[1, 13]], b[[1, 14]], b[[1, 15]], b[[1, 16]], b[[1, 17]], b[[1, 18]], b[[1, 22]], b[[1, 23]], b[[1, 24]], b[[1, 19]], b[[1, 20]], b[[1, 21]], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {b[[2, 1]], b[[2, 2]], b[[2, 3]], b[[2, 4]], b[[2, 5]], b[[2, 6]], b[[2, 10]], b[[2, 11]], b[[2, 12]], b[[2, 7]], b[[2, 8]], b[[2, 9]], b[[2, 10]], b[[2, 11]], b[[2, 12]], b[[2, 7]], b[[2, 8]], b[[2, 9]], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, b[[2, 13]], b[[2, 14]], b[[2, 15]], b[[2, 16]], b[[2, 17]], b[[2, 18]], b[[2, 22]], b[[2, 23]], b[[2, 24]], b[[2, 19]], b[[2, 20]], b[[2, 21]], b[[2, 22]], b[[2, 23]], b[[2, 24]], b[[2, 19]], b[[2, 20]], b[[2, 21]], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} This second row is not all zero and I believe some is correct, but it is still in error. I do not know how to ask you a question that you will understand. You do not know how to tell me an answer that I will understand. For your last question to transform code into Mathematica I do not know what S[k] is. Perhaps this will help you B = Table[0, {150}, {150}]; For[k = 1, k <= 16, k++, Table[If[i <= j, B[[i, j]] = B[[i, j]] + A[[Position[S[k], i], Position[S[k], j]]]], {i, S[k]}, {j, S[k]}] ] but I cannot test this for you because I do not have information to understand this. URL: ,

 Subject (listing for 'Help with creating matrix from another matrix') Author Date Posted Help with creating matrix from another matrix Anton Siswo 03/24/13 01:15am Re: Help with creating matrix from another matrix Bill Simpson 03/24/13 11:53pm Re: Re: Help with creating matrix from another ... Anton Siswo 03/25/13 11:35am Re: Re: Re: Help with creating matrix from anot... Bill Simpson 03/25/13 7:32pm Re: Re: Re: Help with creating matrix from anot... Bill Simpson 03/25/13 10:20pm Re: Re: Re: Re: Help with creating matrix from ... Anton Siswo 03/31/13 7:22pm Re: Re: Re: Re: Re: Help with creating matrix f... Bill Simpson 04/01/13 00:06am Re: Re: Re: Re: Re: Re: Help with creating matr... Anton Siswo 04/01/13 5:52pm Re: Re: Re: Re: Re: Help with creating matrix f... Bill Simpson 04/01/13 10:44am Re: Re: Re: Re: Re: Re: Help with creating matr... Anton Siswo 04/08/13 04:52am Re: Re: Re: Re: Re: Re: Re: Help with creating ... Bill Simpson 04/09/13 8:35pm Re: Re: Re: Re: Re: Re: Re: Re: Help with creat... Anton Siswo 04/11/13 10:58am Re: Re: Re: Re: Re: Re: Re: Help with creating ... Bill Simpson 04/09/13 9:54pm Re: Re: Re: Re: Re: Re: Re: Re: Help with creat... Anton Siswo 04/10/13 9:41pm Re: Re: Re: Re: Re: Re: Re: Re: Re: Help with c... Bill Simpson 04/12/13 00:35am Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Help wi... Anton Siswo 04/16/13 07:19am Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Hel... Bill Simpson 04/16/13 7:48pm Re: Help with creating matrix from another matrix Anton Siswo 03/26/13 11:29pm
 < Previous Comment | Next Comment > Help | Reply To Comment | Reply To Topic