Skip to main content
expanded answer
Source Link

I suspect the reason for the warning is because:

NSum first localizes the values of all variables, then evaluates f with the variables being symbolic, and then repeatedly evaluates the result numerically.

NSum has attribute HoldAll, and effectively uses Block to localize variables.

So under the hood it is doing something like

Clear[n]
{1, 2}[[n]] (* triggers your error *)

n = 1;
{1, 2}[[n]] (* produces your answer *)

To get rid of the warning does this work for you?

test = {1, 2};
NSum[Indexed[test, n], {n, 1, 2}] (*3.*)

I suspect the reason for the warning is because:

NSum first localizes the values of all variables, then evaluates f with the variables being symbolic, and then repeatedly evaluates the result numerically.

NSum has attribute HoldAll, and effectively uses Block to localize variables.


To get rid of the warning does this work for you?

test = {1, 2};
NSum[Indexed[test, n], {n, 1, 2}] (*3.*)

I suspect the reason for the warning is because:

NSum first localizes the values of all variables, then evaluates f with the variables being symbolic, and then repeatedly evaluates the result numerically.

NSum has attribute HoldAll, and effectively uses Block to localize variables.

So under the hood it is doing something like

Clear[n]
{1, 2}[[n]] (* triggers your error *)

n = 1;
{1, 2}[[n]] (* produces your answer *)

To get rid of the warning does this work for you?

test = {1, 2};
NSum[Indexed[test, n], {n, 1, 2}] (*3.*)
Source Link

I suspect the reason for the warning is because:

NSum first localizes the values of all variables, then evaluates f with the variables being symbolic, and then repeatedly evaluates the result numerically.

NSum has attribute HoldAll, and effectively uses Block to localize variables.


To get rid of the warning does this work for you?

test = {1, 2};
NSum[Indexed[test, n], {n, 1, 2}] (*3.*)