I try in mathematica to define a function using subscripted variables and subscripted parameters. It seems however that mathematica is not able to treat these subscripted variables as symbols. Indeed, when I use non subscripted variables and parameters it "works".
For example:
In: Function[##,Subscript[A, 2] Subscript[x, 1] ] & @@ {Subscript[A, 2]}
Out:Function::flpar: Parameter specification Subscript[A, 2] in Subscript[A, 2]\[Function]Subscript[A, 2] Subscript[x, 1] should be a symbol or a list of symbols.
But if I do:
In: Function[##,A x] & @@ {A}
Out: a\[Function]a x
(It is "working")
Any Idea?
Thanks in advance,
Camille
>>
>I try in mathematica to define a function using subscripted
>variables and subscripted parameters. It seems however that
>mathematica is not able to treat these subscripted variables as
>symbols. Indeed, when I use non subscripted variables and parameters
>it "works".
If you want to use subscribed variables like ordinary
Mathematica symbols, load the package Notation and make use of
Symbolize. But, if you are like me, you will find this more
trouble than it is worth.
The easiest way to make subscripted variables into symbols is to use Symbolize from the Notation package.
Needs["Notation`"];
Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]]]
See http://stackoverflow.com/q/5481216/421225 for more details.
http://sites.google.com/site/andrewjmoylan/mathematica
http://sites.google.com/site/andrewjmoylan/Moylan.zip
Description from the web-page: "This package makes Mathematica treat all the
subscripts in your notebook as symbols. I used it for a long time because
it's standard in physics to treat symbols like r, r0, and rcore as unique
variables.
If you set SubscriptSymbols = True, every expression with head SubscriptBox
will be transparently converted into a symbol; and that symbol will display
as the corresponding SubscriptBoxes on output. You won't normally need to
know about the underlying proxy symbol, but you can use Information[] to
find out its name."
"Camille" <camille...@gmail.com> wrote:
news:j28emt$3fa$1...@smc.vnet.net...
That is not a complaint; I'm having a lot of fun with Mathematica. But when
I want to think like a programmer, I prefer to narrow my view for
utilitarian purposes. That's why I am using strings -- in effect, building
my own symbol tables.
That's wasteful, I'm sure, but so far I can't figure out the right way to do
it. Has anyone constructed a compiler in Mathematica? If so, that code might
tell the tale.
Ralph
On Wed, Aug 17, 2011 at 5:52 AM, Alexey Popkov <leh...@gmail.com> wrote:
> You may try to use the SubscriptSymbols command from Andrew Moylan's
> package:
>
> http://sites.google.com/site/andrewjmoylan/mathematica
> http://sites.google.com/site/andrewjmoylan/Moylan.zip
>
> Description from the web-page: "This package makes Mathematica treat all
> the
> subscripts in your notebook as symbols. I used it for a long time because
> it's standard in physics to treat symbols like r, r0, and rcore as unique
> variables.
>
> If you set SubscriptSymbols = True, every expression with head SubscriptBox
> will be transparently converted into a symbol; and that symbol will display
> as the corresponding SubscriptBoxes on output. You won't normally need to
> know about the underlying proxy symbol, but you can use Information[] to
> find out its name."
>
>
> "Camille" <camille...@gmail.com> wrote:
> news:j28emt$3fa$1...@smc.vnet.net...
You can convert a string containing correct symbol name to a symbol by using
the Symbol command or by using ToExpression. Note three-argument form of
ToExpression:
ToExpression["symbolName",InputForm,yourFunction]
This form allows you to pass your symbol to arbitrary function with Hold*
attribute without evaluating your symbol.
You can find description of the standard evaluation sequence on the top of
the following Documentation page:
http://reference.wolfram.com/mathematica/tutorial/Evaluation.html
I strongly reccommend to become familiar with the standard evaluation
sequence bacause it explains many "strange" aspects of expression evaluation
in Mathematica. Some experiments with the Trace command my help with
understanding it significantly. You could also try to use WReach's traceView
utilities:
http://stackoverflow.com/questions/5459735/the-clearest-way-to-represent-mathematicas-evaluation-sequence