Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to take two lists (each list contains the number of moles of a chemical). I have a function calledFraction that takes the each entry of the list and then calculates the mole fraction of Chloroform. Each entry in the new list should be the mole fraction calculated by taking
molesChloroform[[1]]/(molesChloroform[[1]] + molesAcetone[[1]]

Here is what I have tried:

molesChloroform = {0.125, 0.100, 0.0625, 0.0375}
molesAcetone = {0.027, 0.068, 0.0952, 0.136}
moleFraction[molesA_, molesB_] = molesA/(molesA + molesB)
{moleFraction[#1, #2]} & @@@ {molesChloroform[[1 ;;]], 
  molesAcetone[[1 ;;]]}
Out[23]= {{0.555556}, {0.284211}}

This is not the correct output.

share|improve this question
Do you get the correct output if you change @@@ to @@? Or, better yet, if you use moleFraction[molesChloroform,molesAcetone ]? – kglr Apr 5 '13 at 5:04
yes I do. Thank you. I don't know why I didn't think your simpler solution wouldn't work. both give the same output. And i have verified it is correct. – olliepower Apr 5 '13 at 5:14
up vote 3 down vote accepted

A solution to compute the ratio for any two lists of mole values, based on MapThread:

mf[mA_, mB_] := MapThread[#1/(#1 + #2) &, {mA, mB}]


(*{0.822368, 0.595238, 0.396322, 0.216138}*)
share|improve this answer

I changed

{moleFraction[#1, #2]} & @@@ {molesChloroform[[1 ;;]], 
 molesAcetone[[1 ;;]]}


{moleFraction[#1, #2]} & @@ {molesChloroform[[1 ;;]], 
 molesAcetone[[1 ;;]]}

And got this correct result:

{0.822368, 0.595238, 0.396322, 0.216138}


moleFraction[molesChloroform, molesAcetone]

give the same result.

share|improve this answer
Yes, all sub-operations are Listable therefore the function moleFraction can be used directly. See Case #4 here. – Mr.Wizard Apr 5 '13 at 7:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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