0

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?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
physicsGuy
  • 557
  • 3
  • 9

1 Answers1

1

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
m_goldberg
  • 107,779
  • 16
  • 103
  • 257