MathGroup Archive 2004

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

Search the Archive

Re: Interpretation of subscripts

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48082] Re: Interpretation of subscripts
  • From: drbob at bigfoot.com (Bobby R. Treat)
  • Date: Tue, 11 May 2004 05:20:04 -0400 (EDT)
  • References: <c7hrfh$bjb$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I rarely use subscripted symbols directly. Instead, I use the
following function:

subFunction[a_Symbol] := 
  Block[{aa = ToString[a]}, 
   MakeExpression[SubscriptBox[
       ToString[a], i_], f_] := 
     MakeExpression[RowBox[{ToString[a], 
        "[", i, "]"}]]; 
    MakeBoxes[a[i_], f_] := 
     SubscriptBox[MakeBoxes[a, f], 
      MakeBoxes[i, f]]]

Invoke that on the symbol m with

subFunction[m]

Now if you type m[Sun], it looks like the subscripted form in output,
and if you input the subscripted form it looks subscripted but is
evaluated as m[Sun]. If you want it to have the subscripted look in an
input line either input it subscripted or else highlight it,
right-click, and select Evaluate in Place. (The latter method doesn't
work if m[Sun] has a value, of course.)

subFunction[m]
Solve[m[Sun]^2 == m[Sun] + 1]
{{m[Sun] -> (1/2)*
     (1 - Sqrt[5])}, 
  {m[Sun] -> (1/2)*
     (1 + Sqrt[5])}}

That's InputForm; in the actual output, m[Sun] is the subscripted
form.

Now enter

m/@Range[10]

or

m/@{Sun,Moon,Earth}

and check out the results.

Bobby

dquark at gmx.de (Guido) wrote in message news:<c7hrfh$bjb$1 at smc.vnet.net>...
> I wanted to solve a differential equation via DSolve. When naming the
> constants with subscripts (e.g. for the mass of the sun M_Sun with the
> word Sun on the line), Mathematica 5 in some way misinterpreted this
> and told me:
>   DSolve::bvfail : For some branches of the general solution, unable
> to solve the conditions.
> It works, when I leave out the subscripts and name the mass of the sun
> simply M and the mass of a planet m, but for optical reasons it would
> be nice to have subscripts for better understanding.
> I also tried this with Mathematica 4.2 in university - and it worked
> fine, but I only have version 5 in my office.
> In help files it is said, that Mathematica wouldn't interprete
> subscipts in any other way than as names, but obviously it does...
> Is there any point in preferences to tell the programm how it should
> handle these things?
> 
> I'm grateful for any help
> 
> Guido


  • Prev by Date: Re: how to save a mathematica-made imagebox.image as jpg, gif, bmp in c#/.netlink?
  • Next by Date: Re: Working with binaries
  • Previous by thread: Re: Interpretation of subscripts
  • Next by thread: RE : Building List