Re: Unit conversion of a list of quantities
- To: mathgroup at smc.vnet.net
- Subject: [mg131981] Re: Unit conversion of a list of quantities
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Fri, 8 Nov 2013 16:25:05 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
On 11/7/13 at 12:28 AM, mariusz.sapinski at gmail.com (mariusz sapinski) wrote: >I have the following lists: Edep = {4.9491200000000017`*^-14 >Joules, 1.8669264000000004`*^-14 Joules, >6.223088000000001`*^-15 Joules} >mass = {0.043937500000000004` g, 0.06987` g, 0.02329` g} >I want to calculate dose: dose = Edep/mass >I get another list (of Quantities): >{(1.1264*10^-12 Joules)/g, (2.672*10^-13 Joules)/g, ( >2.672*10^-13 Joules)/g} No you didn't get a list of Quantities. Using your code above, look at the FullForm of say the first item in you list. You will get the result: In[8]:= FullForm[First@dose] Out[8]//FullForm= Times[1.1264000000000003`*^-12,Power[g,-1],Joules] Now set up Edep and mass as Quantities as follows: In[9]:= Edep = Quantity[#, "Joules"] & /@ {4.9491200000000017`*^-14 , 1.8669264000000004`*^-14 , 6.223088000000001`*^-15}; mass = Quantity[#, "Grams"] & /@ {0.043937500000000004, 0.06987, 0.02329}; In[11]:= dose = Edep/mass Out[11]= {1.1264*10^-12 J/g,2.672*10^-13 J/g,2.672*10^-13 J/g} Now look at the FullForm of the first item In[12]:= FullForm[First@dose] Out[12]//FullForm= Quantity[1.1264000000000003`*^-12,Times[Power["Grams",-1],"Joules"]] Note, it has Head Quantity not Times. So, now you can do In[13]:= UnitConvert[dose, "Joules"/"Kilograms"] Out[13]= {1.1264*10^-9 J/kg,2.672*10^-10 J/kg,2.672*10^-10 J/kg} getting the desired result