Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 ]? –  kguler 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
add comment

2 Answers 2

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}]

mf[molesChloroform,molesAcetone]

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

I changed

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

to

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

And got this correct result:

{0.822368, 0.595238, 0.396322, 0.216138}

Also

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
add comment

Your Answer

 
discard

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.