Skip to main content
Tweeted twitter.com/#!/StackMma/status/188373030219689984
added 27 characters in body
Source Link
Albert Retey
  • 23.6k
  • 60
  • 104

I have the following code:

Subscript[f, i_][x_] := Block[{a},
  Subscript[a, i] = 3 x;
  Subscript[a, 1]
]

If I evaluate for example Subscript[f,1][2], thenit evaluates to 6. After that asking what Subscript[a,1] is also gives me six. However, I want a to be a local variable.

My question: how can I define a local variable while using indices...?

Note: the original post mentioned that evaluating Subscript[f,1][2] = 6 would lead to the described behaviour, which just isn't true. A reasonable guess is that this was ment to mean that Subscript[f,1][2] was to be evaluated and it would evaluate to 6 (which it does). After that Subscript[a,1] will evaluate to 6 as reported.

I have the following code:

Subscript[f, i_][x_] := Block[{a},
  Subscript[a, i] = 3 x;
  Subscript[a, 1]
]

If I evaluate for example Subscript[f,1][2], then asking what Subscript[a,1] is also gives me six. However, I want a to be a local variable.

My question: how can I define a local variable while using indices...?

Note: the original post mentioned that evaluating Subscript[f,1][2] = 6 would lead to the described behaviour, which just isn't true. A reasonable guess is that this was ment to mean that Subscript[f,1][2] was to be evaluated and it would evaluate to 6 (which it does). After that Subscript[a,1] will evaluate to 6 as reported.

I have the following code:

Subscript[f, i_][x_] := Block[{a},
  Subscript[a, i] = 3 x;
  Subscript[a, 1]
]

If I evaluate for example Subscript[f,1][2], it evaluates to 6. After that asking what Subscript[a,1] is also gives me six. However, I want a to be a local variable.

My question: how can I define a local variable while using indices...?

Note: the original post mentioned that evaluating Subscript[f,1][2] = 6 would lead to the described behaviour, which just isn't true. A reasonable guess is that this was ment to mean that Subscript[f,1][2] was to be evaluated and it would evaluate to 6 (which it does). After that Subscript[a,1] will evaluate to 6 as reported.

added correction based on guess and explanation about that correction and guess
Source Link
Albert Retey
  • 23.6k
  • 60
  • 104

I have the following code:

Subscript[f, i_][x_] := Block[{a},
  Subscript[a, i] = 3 x;
  Subscript[a, 1]
]

If I evaluate for example Subscript[f,1][2] = 6, then asking what Subscript[a,1] is also gives me six. However However, I want a to be a local variable.

My question: how can I define a local variable while using indices...?

Note: the original post mentioned that evaluating Subscript[f,1][2] = 6 would lead to the described behaviour, which just isn't true. A reasonable guess is that this was ment to mean that Subscript[f,1][2] was to be evaluated and it would evaluate to 6 (which it does). After that Subscript[a,1] will evaluate to 6 as reported.

I have the following code:

Subscript[f, i_][x_] := Block[{a},
  Subscript[a, i] = 3 x;
  Subscript[a, 1]
]

If I evaluate for example Subscript[f,1][2] = 6, then asking what Subscript[a,1] is also gives me six. However, I want a to be a local variable.

My question: how can I define a local variable while using indices...?

I have the following code:

Subscript[f, i_][x_] := Block[{a},
  Subscript[a, i] = 3 x;
  Subscript[a, 1]
]

If I evaluate for example Subscript[f,1][2], then asking what Subscript[a,1] is also gives me six. However, I want a to be a local variable.

My question: how can I define a local variable while using indices...?

Note: the original post mentioned that evaluating Subscript[f,1][2] = 6 would lead to the described behaviour, which just isn't true. A reasonable guess is that this was ment to mean that Subscript[f,1][2] was to be evaluated and it would evaluate to 6 (which it does). After that Subscript[a,1] will evaluate to 6 as reported.

formatted code; retagged.
Source Link
rcollyer
  • 34.1k
  • 7
  • 94
  • 194

I have the following code:

Subscript[f, i_][x_] := Block[{a}, Subscript[a, i] = 3 x; Subscript[a, 1] ]

Subscript[f, i_][x_] := Block[{a},
  Subscript[a, i] = 3 x;
  Subscript[a, 1]
]

If I evaluate for example f_1[2] = 6Subscript[f,1][2] = 6, then asking what a_1Subscript[a,1] is also gives me six. However, I want aa to be a local variable.

My question: how can I define a local variable while using indices...?

I have the following code:

Subscript[f, i_][x_] := Block[{a}, Subscript[a, i] = 3 x; Subscript[a, 1] ]

If I evaluate for example f_1[2] = 6, then asking what a_1 is also gives me six. However, I want a to be a local variable.

My question: how can I define a local variable while using indices...?

I have the following code:

Subscript[f, i_][x_] := Block[{a},
  Subscript[a, i] = 3 x;
  Subscript[a, 1]
]

If I evaluate for example Subscript[f,1][2] = 6, then asking what Subscript[a,1] is also gives me six. However, I want a to be a local variable.

My question: how can I define a local variable while using indices...?

Post Migrated Here from math.stackexchange.com (revisions)
Source Link
Bee
Bee
Loading