Hi,
I'd like to be able to calculate the molar mass of chemical compounds
using a Lua module so that I could use the output in my infoboxes for
chemical compounds and drugs alike. The problem is, I haven't the
foggiest how to set up a module, even one that sounds so simple. I was
hoping that someone may be able to set things up for me, or at least
show me how to do so myself^1 if I gave them the basic idea of what I
was hoping this module would do.
Say we call the module Molar mass calculator (i.e., @ /Module:Molar mass
calculator/ on my local Wiki is where its Lua code is and the template
that invokes it /Template:Molar mass calculator/^2 ). I was thinking of
the Lua module using a pair of vectors one (A⇀\vec{A}) containing the
user-defined variables^3 of all 84 chemical elements found in
appreciable quantities in nature and the other containing the average
atomic mass for all these elements (M⇀\vec{M}). Then doing the Lua
equivalent to a dot product (i.e., A⇀⋅M⇀=∑i=184AiMi\vec{A}\cdot \vec{M}
= \sum_{i=0}^{84} A_i M_i) between these two vectors and using the
result as the module's output which would then//used by the template as
its output.
Footnotes
1. Keeping in mind I am a programming noob, especially when it
comes to Lua, so talk to me like a maths guy that just
understands a little MATLAB, NumPy, SciPy, Python and Wikitext
and no other programming languages as this is fairly accurate.
2. /Template:Molar mass calculator/, presently has this Wikitext
(hence if a change is required please do alert me to it):
{{#invoke:Molar mass calculator}}<noinclude>{{Clr}}
{{documentation}}</noinclude>
3. These variables are those provided to /Template:Molar mass
calculator/ as arguments. For example, if I want to call the
template in a Wiki page it may look like this for Ethanol (C_2
H_6 O)
{{Molar mass calculator
|C = 2
|H = 6
|O = 1
}}
and should provide the output of 46.0694 g/mol.
Thanks for your time,
Brenton