Reputation: 13051
I would like to define an object/symbol in mathematica which will have several parameters, for example, something like: S=(1-t)({b_i}^x,{b_i}^y)+t({b_{i+1}}^x,{b_{i+1}}^y)
(sort of LaTeX notation). In the example I'm trying to describe the line segment connecting two points b_i
and b_{i+1}
.
How can I define such an object in mathematica
?
I found the following two questions:
But I'm not sure that I am using them correctly. What I have done is the following. First I invoked:
Needs["Notation`"];
Symbolize[
ParsedBoxWrapper[
SubscriptBox["\[SelectionPlaceholder]", "\[Placeholder]"]]]
Symbolize[
ParsedBoxWrapper[
SuperscriptBox["\[SelectionPlaceholder]", "\[Placeholder]"]]]
Then, I actually defined the object:
(1 - t) {Subscript[b, i]^x, Subscript[b, i]^y} +
t {Subscript[b, i + 1]^x, Subscript[b, i + 1]^y}
Is this the right way to do what I want?
Upvotes: 4
Views: 4855
Reputation: 16232
I'm not entirely sure I understand what you want. The 'object' you are talking about
(1 - t) {Subscript[b, i]^x, Subscript[b, i]^y} +
t {Subscript[b, i + 1]^x, Subscript[b, i + 1]^y}
isn't really a single entity, but the sum of two lists each consisting of two components. So, I assume that you really want to define Subscript[b, i]^x
as a symbol.
You can do this with Symbolize
from the Notation
package. It's absolutely crucial, though, that you use the template generated when you press the Symbolize button on the Notation palette (you get this upon running << Notation`
). Then enter your compound variable. I'll be assuming the superscript x and y are fixed symbols and the subscript i
s are variable:
One more thing:
It might not be a good idea to use Subscript[b, i]^y
as you'd lose the ability to raise subscripted variables to the power x and y (a minor loss, but still). Instead you might want to use Subsuperscript[b,i,y]
. Please note that the sentence in the 'More information' part of the Subsuperscript
documentation page seems to be patently wrong. It says:
To enter a subsuperscript in a notebook, use either Ctrl+_ to begin a regular subscript or Ctrl+^ to begin a regular superscript. After typing the first script, use Ctrl+% to move to the opposite script position. Ctrl+Space moves out of the subscript or superscript position.
If you do a FullForm
on the resulting object you'll see you have made a Subscript[b, i]^y
instead. To get the symbol for pasting in the Symbolize template I see no other solution than typing Subsuperscript[b, i_, y]
, evaluating, and copying the result to the template.
Upvotes: 6
Reputation: 4420
Further to Sjoerd's answer: Since you say the symbol S
takes various parameters, I think you might want to explore theSetDelayed
method to define a function with parameters. Assumuing that you do want S
to be vector-valued with two points, then something like the following would define S
in the way you want it.
S[x_,y_,t_,i_]:= (1-t) * {b[i]^x,b[i]^y} + t * {(b[i+1])^x,(b[i+1])^y}
The question then is whether you really need the subscripting. Sjoerd's answer shows how this is done using the Notation package, but you should consider whether this additional complication is necessary to your analysis.
EDIT in response to rcollyer's very helpful comment
You can use Format
to define a TraditionalForm
representations for a custom function. This is similar to defining UpValues
, but relates to the representation rather than the re-writing rules.
Something like the following should work:
Format[S[x_,y_,t_,i_],TraditionalForm] :=
(1 - t) {Subscript[b, i]^x, Subscript[b, i]^y} +
t {Subscript[b, i + 1]^x, Subscript[b, i + 1]^y}
Upvotes: 1