Vectors and Matrices

M_HC is our matrix that maps the first three hydrocarbons to number of hydrogens and carbons

In[1]:=

M_HC = { {4, 1},  {8, 3},  {10, 4} }

M_HC//MatrixForm

Out[1]=

{{4, 1}, {8, 3}, {10, 4}}

Out[2]//MatrixForm=

( {{4, 1}, {8, 3}, {10, 4}} )

In[3]:=

PTmatrix = { {α, β},  {γ, δ},  {ε, φ} } ;

PTmatrix//MatrixForm

Out[4]//MatrixForm=

( {{α, β}, {γ, δ}, {ε, φ}} )

In[5]:=

MPT   = M_HC .   PTmatrix

Dot :: dotsh : Tensors  {{4, 1}, {8, 3}, {10, 4}} and {{α, β}, {γ, δ}, {ε, φ}} have incompatible shapes. More…

Out[5]=

{{4, 1}, {8, 3}, {10, 4}} . {{α, β}, {γ, δ}, {ε, φ}}

The matrix multiplication does not work because the sizes are inconsistent.

In[6]:=

Clear[MPT]

In[7]:=

MPT = Transpose[M_HC] .   PTmatrix ;

MPT//MatrixForm

Out[8]//MatrixForm=

( {{4 α + 8 γ + 10 ε, 4 β + 8 δ + 10 φ}, {α + 3 γ + 4 ε, β + 3 δ + 4 φ}} )

In[9]:=

MPTinverse = Factor[Inverse[MPT]] ;

MPTinverse//MatrixForm

Out[10]//MatrixForm=

In[11]:=

Det[MPT]

Out[11]=

-4 β γ + 4 α δ - 6 β ε - 2 δ ε + 6 α φ + 2 γ φ

In[12]:=

RowReduce[M_HC]//MatrixForm

Out[12]//MatrixForm=

( {{1, 0}, {0, 1}, {0, 0}} )

Same example for water and water complexes: use the matrix watmat to store molecular formulas for each type of molecule in the system

In[13]:=

watmat = {{2, 4}, {1, 2}} ;

watmat//MatrixForm

Out[14]//MatrixForm=

( {{2, 4}, {1, 2}} )

The vector molvec is used to store the number of each kind of molecule

In[15]:=

molvec = {h20, h402}

Out[15]=

{h20, h402}

The vector atomvec is used to store the number of each atomic species that is present

In[16]:=

atomvec = {h, o}

Out[16]=

{h, o}

In[17]:=

atomvec//MatrixForm

Out[17]//MatrixForm=

( {{h}, {o}} )

The vector eq is now defined and its two elements are equations that give the number of hydrogen atoms and the number of oxygen atoms:

In[18]:=

eq[1] = (watmat . molvec)[[1]] == atomvec[[1]]

Out[18]=

2 h20 + 4 h402 == h

In[19]:=

eq[2] =    (watmat . molvec)[[2]] == atomvec[[2]]

Out[19]=

h20 + 2 h402 == o

In[20]:=

? Eliminate

Eliminate[eqns, vars] eliminates variables between a set of simultaneous equations. More…

In[21]:=

Eliminate[{eq[1], eq[2]}, molvec]

Out[21]=

2 o == h


Created by Mathematica  (September 21, 2005) Valid XHTML 1.1!