I have the following function
lFreqPhylo[a_, Q_, b_, p_] := Sum[Log[freqFunction[r[[p]][[i]], L[[p]][[i]], a, Q, b, {i, 1, nbranches[[p]]}];
The objects L, r and nbranches are simply lists of data, and the argument p tells the function which dataset to refer to.
I'd like to define a function which sums all of the datasets (here n=2) and uses a different argument a and b for each dataset, so to write it our by hand,
lFreqPhylo[a1, Q, b1, 1] + lFreqPhylo[a2, Q, b2, 2]
To this end, I defined two lists,
A = {a1,a2}
and
B = {b1,b2}
(This list has more elements but I'm giving the example of 2 elements to keep it simple.) What this means is that I'd need to pass the lists A, B and the index to each list (p in lFreqPhylo) to a new function lFreq. The following approach however failed:
lFreq[A__, B__, Q_] := Sum[lFreqPhylo[A[[p]], Q, B[[p]], p], {p, 1, 2}]; (*Doesn't work!*)
How can I pass the two lists, A and B, to the function lFreqPhylo such that I can (a) use the 'Sum[...]' expression on the right hand side, (b) use the list elements, a1, a2, b1 and b2, as arguments of the function?
Thanks in advance, Rafal
Well, problem is I have two lists and need to pass an index of the list as an argument. So following your advice, having defined two lists,
A = {a1,a2}; B = {b1,b2};
I did
and now it works. But what if I have
where i is the index of the element of the list (1 or 2)? How do I define f2 then?
– Rafal May 27 '14 at 13:36lFreq[A_, B_, Q_]and it works as expected; no? – kglr May 27 '14 at 22:10