I am trying to create two sets, then merge them (they have one common element) and then take the total of the new set.
Let's call them set1
and set2
while their union is called set
set1[t_,gh_,ga_]:=If[gh==0,Reap[For[i=0,i<=10,i++,Sow[fn[0,i,t,gh,ga]]]][[2,1]],{}];
set2[t_,gh_,ga_]:=If[ga==0,Reap[For[i=0,i<=10,i++,Sow[fn[i,0,t,gh,ga]]]][[2,1]],{}];
and
set[t_, gh_, ga_] :=
Union[set1[t, gh, ga], set2[t, gh, ga]];
I call them by setting t=gh=ga=0
and I get this:
set1[0,0,0]
{fn[0,0,0,0,0],fn[0,1,0,0,0],fn[0,2,0,0,0],fn[0,3,0,0,0],fn[0,4,0,0,0],fn[0,5,0,0,0],fn[0,6,0,0,0],fn[0,7,0,0,0],fn[0,8,0,0,0],fn[0,9,0,0,0],fn[0,10,0,0,0]}
set2[0,0,0]
{fn[0,0,0,0,0],fn[1,0,0,0,0],fn[2,0,0,0,0],fn[3,0,0,0,0],fn[4,0,0,0,0],fn[5,0,0,0,0],fn[6,0,0,0,0],fn[7,0,0,0,0],fn[8,0,0,0,0],fn[9,0,0,0,0],fn[10,0,0,0,0]}
and finally
set[0,0,0]
{fn[0,0,0,0,0],fn[0,1,0,0,0],fn[0,2,0,0,0],fn[0,3,0,0,0],fn[0,4,0,0,0],fn[0,5,0,0,0],fn[0,6,0,0,0],fn[0,7,0,0,0],fn[0,8,0,0,0],fn[0,9,0,0,0],fn[0,10,0,0,0],fn[1,0,0,0,0],fn[2,0,0,0,0],fn[3,0,0,0,0],fn[4,0,0,0,0],fn[5,0,0,0,0],fn[6,0,0,0,0],fn[7,0,0,0,0],fn[8,0,0,0,0],fn[9,0,0,0,0],fn[10,0,0,0,0]}
and then i simply ask for set[0,0,0]//Total
.
Here is the thing. When I feed my program with some initial values everything works fine, unless the initial values are such that
fn[1,0,0,0,0]
is equal to fn[0,1,0,0,0]
and so on, for example suppose that they are both equao to 0.2
since two sets (set1,set2) are equal after evaluation for example:
set1 = {0.20, 0.30, 0.40}
set2 = {0.20, 0.30, 0.40}
when I ask for their union I get set = {0.20, 0.30, 0.40}
and later on I get half the total I was supposed to get: set[0,0,0]//Total = 0.90
while I was expecting 1.80
So basically I need to form set
before fn is evaluated. It is crucial to define fn though before those sets.
I tried hold, Unevaluated, Cell [Evaluatable->False] and other functions/properties but none workded. Any idea?
i
ofset2
at1
rather than0
, and then usingJoin
instead ofUnion
? $\endgroup$set1
as follows:set1[t_, 0, ga_] := fn[0, #, t, 0, ga] & /@ Range[0, 10]; set1[t_, gh_, ga_] := {};
(and similarly forset2
). $\endgroup$set1[t_,gh_,ga_]:=If[gh==0,Reap[For[i=0,i<=10,i++,Sow[fn[0,i,t,gh,ga]]]][[2,1]],{}]; set2[t_,gh_,ga_]:=If[ga==0,Reap[For[i=0,i<=10,i++,Sow[fn[i,0,t,gh,ga]]]][[2,1]],{}]; NoGoalSet[t_,gh_,ga_]:=Delete[Join[NoGoalHomeSet[t,gh,ga],NoGoalAwaySet[t,gh,ga]],1];
$\endgroup$Deleteduplicates
worked the very same way asUnion
, so I just \ usedDelete
by deleting the 1 st element of my list (0, 0) which is basically what you suggested. $\endgroup$