0
$\begingroup$

Using subscripts would significantly improve the structure of my code. Until now I used the following two lines to implement this.

Needs["Notation`"];
Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]]];

This allows me to define a symbol like

Subscript[a, r] = 10

This works fine up to the point where I want to define e.g.

f[r_] = r Subscript[a, r][r]

I want the result to be

f[x] = 10 x

The problem is that Mathematica recognizes the r in Subscript[a, r] as an variable. Hence I can not use the subscript in such a case. Is there an easy way to solve this?

$\endgroup$

migrated from math.stackexchange.com Jul 21 '15 at 12:48

This question came from our site for people studying math at any level and professionals in related fields.

  • $\begingroup$ Related: Can me use letter with a subscript as a variable?. $\endgroup$ – dionys Jul 21 '15 at 13:04
  • 3
    $\begingroup$ My experience tells me that you will disappointed with the approach you are taking -- introducing subscripted variables will cause more problems than improvements to the structure of your code. $\endgroup$ – m_goldberg Jul 21 '15 at 13:51
1
$\begingroup$

I think you may want

With[{u = Subscript[a, r]}, f[r_] := u r]

then

f[x]
10 x

Or perhaps you want to keep Subscript[a, r] as a free variable.

g[x_] := Subscript[a, r] x
g[x]
10 x
Subscript[a, r] = 42; g[x]
42 x
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.