Tag Info

New answers tagged

1

This is NOT an answer but more like an observation. Fresh start, win7 x64, MMA V10.0.1 X64: The first input should assign value to ans, and I check ans EQUALS the last output (%1)?? So no problem when you type the first TWO lines together?? Only is a problem is you type them separately? so executed twice??


4

The behaviour we see here is due to Set performing limited evaluation of its left-hand-side prior to the assignment. Set Evaluates the Left-Hand-Side Despite the fact that Set has the attribute HoldFirst, it performs a special kind of evaluation upon its left-hand-side prior to performing the assignment. Specifically, if the left-hand-side has a head and ...


6

Evaluation happens too late, but you can fix it by forcing evaluation first: Remove[a] index = {3, 4}; Evaluate[a @@ index] = 5; a @@ index 5 This can only be done on the initial definition though. After that a[Sequence @@ index] = 6; a @@ index 6


6

Updated 14-10-2014 see solution at the end. This answer is basically for documentation of the problem. The credit goes mainly to the people participating in the comments. Diagnostics I can reproduce you observation on two different computers both, Windows 7 Pro 64, SP 1 running Mathematica 10.0.1. The "feature" appears for list of 11 or more random ...


0

If xn has not yet a value, x1=x2=...=xn will set all variables to xn, and then if you do xn=3 all of them will evaluate to 3. If xn already has a value at the point of assignment, you can temporarily unset it using Block. For example c=1 Block[{c}, a=b=c] {a, b, c} (* ==> {1, 1, 1} *) c=2 {a, b, c} (* ==> {2, 2, 2} *) However, in that case ...


6

You can "unify" several variables in the following way x /: HoldPattern[x[k_] = val_] /; 1 <= k <= 10 := (shared = val) x[k_] /; 1 <= k <= 10 && ValueQ[shared] := shared x[2] (* x[2] *) x[3] = 1 (* 1 *) x[9] (* 1 *) x[8] = 0 (* 0 *) x[7] (* 0 *) x[2] = x[3] + 1 (* like shared++ *) (* 1 *) x[11] (* x[11] *) The same for ...


1

You could define a function which creates an array of n constant value var[constant_, n_] := x = ConstantArray[constant, n] For e.g we can make an array of size 5 having 3 as the constant value for all elements as follows var[3, 5] (*{3, 3, 3, 3, 3}*) Since x is equated to this function you can call each array element as follows x[[1]] (*3*) So now ...


7

You can delay-set the variables of interest to a common variable: Table[x[k] := m, {k, 10}]; m = 4; Table[x[k], {k, 10}] m = 3; Table[x[k], {k, 10}] which produces output {4, 4, 4, 4, 4, 4, 4, 4, 4, 4} {3, 3, 3, 3, 3, 3, 3, 3, 3, 3} This way, whenever m is altered, the rest of the x[k] adapt accordingly. I'm not quite sure how to make it so that ...



Top 50 recent answers are included