[LON-CAPA-users] sharing variables among questions
Fri, 4 Mar 2005 11:54:18 -0700 (MST)
> Is there a way to define variables that could be used in multiple
> problems? For example, let's say you want to use a set of molecular masses
> in several problems. Rather than copy the problems, is there a way to
> define a variable @mass that could be stored, and then 'called' from
> another specific problem?
You can define a library and then import that library into your problems.
For example, we have a constant library that has many of the fundamental
physics constants. It looks something like this:
# Newton's gravitational constant in m^3/(kg s^2)
$BIG_G = 6.673e-11;
# Acceleration due to gravity near Earth in m/s^2
$SMALL_g = 9.80665;
# Coulomb force constant in N * m^2/C^2
$COULOMB_k = 8.98755e+9;
# Permittivity of free space in F/m
$EPSILON_0 = 8.854187e-12;
# Electron charge in C
$UNIT_CHARGE = 1.60210e-19;
#there are a lot more in there
The file is published in our csmphyslib directory. To import it into our
problems, we just put the following line into our problem.
You will obviously have to change the filename to your library.
With this done, you can use the constants defined in the library. Be
careful that you do not use labels for the constants that might be used
in other places in the problem. For example, you would probably not want
to call your electric charge $e, as there is a chance that later in a
problem there might be another variable called $e.
Hope this helps.