Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Partly solved the problem of obtaining part of a package

  • To: mathgroup at smc.vnet.net
  • Subject: [mg126505] Partly solved the problem of obtaining part of a package
  • From: nanobio9 <kuokan.liang at gmail.com>
  • Date: Tue, 15 May 2012 04:55:41 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

Hi, all,

I posted a question concerning whether we can simply pick up some of
the symbols defined in a package. Unfortunately, the moderation
approach is rather slow that my original question did not appear yet.

Below, I show you some codes that do two things. First, by passing to
it a list of symbol names that I wants to extract from the
"PhysicalConstants" package, it will pick up those constants for me,
and, second, it will take off the units of those constants and returns
their values in SI unit. All of the symbols newly defined while
importing the PhysicalConstants package should have been blocked and
then removed by the $NewSymbol call-back function. Notice that if any
of the symbol is defined before calling this routine, its definition
will be changed by this function call and will not be removed because
redefining it will not invoke the $NewSymbol call-back function.

I still have to think about whether there are better ways of doing
this: perhaps one can even bypass the calling procedure? So your
inputs are still highly desirable.

getConstants[symbs_] :=

 Quiet@Module[{ret = {}, getlist, reslist = {}, val, nvar,
    toremove = {}},
   getlist = {symbs} // Flatten;
   newsymbol = $NewSymbol;
   $NewSymbol = {nvar = #1; val = ToExpression[#2 <> #1];
      If[MemberQ[getlist, nvar], AppendTo[reslist, nvar];
       AppendTo[ret, Evaluate[val][[1]]]]; AppendTo[toremove, nvar]}
&;
   Quiet@Get["PhysicalConstants`"];
   ret = Evaluate[ret];
   ret = ret[[(Position[reslist, #] & /@ getlist) // Flatten]];
   $NewSymbol = newsymbol;
   Remove /@ toremove;
   ret
   ]
{c, hbar} = getConstants[{"SpeedOfLight", "PlanckConstantReduced"}];
Print["c = ", c]; Print["hbar = ", hbar];

c = 299792458

hbar = 1.05457*10^-34



  • Prev by Date: Re: unexpected behaviour of Sum
  • Next by Date: Re: unexpected behaviour of Sum
  • Previous by thread: Load part of a package?
  • Next by thread: equationtreker steamplot