Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum > General > > "Help with creating matrix from another matrix"

Post Reply:
Name:
Email Address:

Please send email when my message is replied to.

Url (optional):
Subject:
Message: view original message?
Attachment (optional):
Please answer this:1+2 =



Original Message (ID '429742') By Bill Simpson:
In Response To 'Re: Re: Help with creating matrix from another ...' --------- I need an answer to a question. I now understand how to do this. In[1]:= x=49;y=50; {Map[Last,Position[a,x]],Map[Last,Position[a,y]]} Out[2]= {{22,13,10,1},{23,14,11,2}} That lets me calculate this. In[3]:= Plus@@Map[Part[b,Sequence@@#]&,Transpose[%]] Out[3]= b[[1,2]]+b[[10,11]]+b[[13,14]]+b[[22,23]] But if I do this. In[4]:= x=1;y=7; {Map[Last,Position[a,x]],Map[Last,Position[a,y]]} Out[5]= {{1},{10,1}} then I do not know what to do. 1 appears one time and 7 appears two times. I understand if the x value or the y value appears zero times then the result is zero. But what do I do if the x and y values appear more than zero times but not the same number of times? Your post does not tell me what to do. If the result should be zero when the x value and y value appear more than zero times, but not the same number of times then this may be your code. In[6]:= Table[ If[ (xp = Map[Last, Position[a, x]]) == {} || (yp = Map[Last, Position[a, y]]) == {} || Length[xp] ≠ Length[yp], 0, Plus @@ Map[Part[b, Sequence @@ #] &, Transpose[{xp, yp}]] ], {x, 1, 150}, {y, 1, 150}]