Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #16196

Re: Unit conversion of a list of quantities

From Bill Rowe <readnews@sbcglobal.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Unit conversion of a list of quantities
Date 2013-11-08 20:45 +0000
Message-ID <l5jii3$lor$1@smc.vnet.net> (permalink)
Organization Time-Warner Telecom

Show all headers | View raw


On 11/7/13 at 12:28 AM, mariusz.sapinski@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

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Unit conversion of a list of quantities Bill Rowe <readnews@sbcglobal.net> - 2013-11-08 20:45 +0000

csiph-web