0
$\begingroup$

I have a list of elements called q and wish to compute Total Multiplicity of each element, and put these values in the list tm.

I need to search for almost equal elements, then list them as a new list with each element's position.

This new list would contain several lists, because there are many elements that are equal relative to each other.

Here is an example:

q list from 0 to 200 correspond to certain values in tm length 201 same as q.

q={0,....,200};
tm={1,3,3,7,3,1,7,8,4}

lst of 3 elements {q,tm}={{1,3},{2,3},{4,3}}

lst1 of 1 elements {q,tm}={{0,1},{5,1}}

and so on...

Here is my code: Look at the last line where tm is calculated.

n = 200; "Whole"
q = 200; "Whole"
na = 1; "System"
nb = 199; "Reservoir"


m[n_, q_] := N[(q + n - 1)!/(q!*(n - 1)!)];

qa = Table[q[j], {j, 0, q}]; 
qb = Reverse[Table[q[j], {j, 0, q}]]; 

qa1 = qa[[All,1]]; 
qb1 = qb[[All,1]]; 

"System Multiplicity"
ma = m[na, qa1]; 

"Reservoir Multiplicity"
mb = m[nb, qb1]; 

"Total Multiplicity"
tm = ma*mb
$\endgroup$
3
$\begingroup$
tm = {1, 3, 3, 7, 3, 1, 7, 8, 4};
A = GroupBy[Transpose[{Range[Length[tm]] - 1, tm}], Last]

<|1 -> {{0, 1}, {5, 1}}, 3 -> {{1, 3}, {2, 3}, {4, 3}}, 7 -> {{3, 7}, {6, 7}}, 8 -> {{7, 8}}, 4 -> {{8, 4}}|>

Values[A]

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

Lookup[A, 1]

{{0, 1}, {5, 1}}

Lookup[A, 3]

{{1, 3}, {2, 3}, {4, 3}}

You say that you want to group "almost equal" elements. I'm not quite sure how you mean this, and propose to use Rounding of the grouping key. For example, grouping by rounding the elements to integer multiples of 3:

A = GroupBy[Transpose[{Range[Length[tm]] - 1, tm}], Round[Last[#], 3] &]

<|0 -> {{0, 1}, {5, 1}}, 3 -> {{1, 3}, {2, 3}, {4, 3}, {8, 4}}, 6 -> {{3, 7}, {6, 7}}, 9 -> {{7, 8}}|>

$\endgroup$
  • $\begingroup$ how do i make list of them separately the new equal list $\endgroup$ – Alrubaie Mar 24 at 19:47
  • $\begingroup$ Have a look at the documentation for Associations: reference.wolfram.com/language/guide/Associations.html $\endgroup$ – Roman Mar 24 at 19:55
  • $\begingroup$ sir how can i ListPlot them !? $\endgroup$ – Alrubaie Mar 24 at 20:10
  • $\begingroup$ cool i did it by Normal $\endgroup$ – Alrubaie Mar 24 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.