For questions relating to assignments to symbols, patterns, or expressions.

learn more… | top users | synonyms (1)

3
votes
2answers
64 views

How to create assignments to OverVector programmatically

I wish to write a function that accepts two lists. The 1st argument is a list of lists, holding the components of a several vectors. Ex.: comp = {{a, b}, {c, d}}. ...
2
votes
3answers
156 views

How can I assign many values each to a different variable? [duplicate]

How can I assign many values each to a different variable? For example, I want to set $a = f(1),\,b = f(2),\,c = f(3),\,\dots,\,z = f(26)$ (generally more variables than these). How can I do this ...
26
votes
5answers
28k views

Assign the results from a Solve to variable(s)

I understand Mathematica can't assign the results of a Solve to the unknowns because there may be more than 1 solution. How can I assign the 4 values of following result to variables?
0
votes
1answer
48 views

Assigining values after the Apply operator

I am writing a script where I need many variables and for ease of usage I denote them as f[k,l,m,n]. I create a list of 4-tuples with the integers I need and I call ...
8
votes
2answers
195 views

How to name a variable with the value of another variable?

A simple but very important (at least for me) question. In some languages for defining a variable, for example, we can do: i=10 "d"&i=30 So I have defined the variable d10, and... d10=30 ...
4
votes
1answer
92 views

Using delayed evaluation on module variables called through an association

I came up with a construct that works well enough for my current use case but has some flaws (at least I suspect it does). Say we have a function that calculates some stuff that takes a while to ...
3
votes
1answer
75 views

Programmatically assign output Hold[…] produced by errors to a variable

expr = Return[1, 2] Return::nofunc: Function 2 not found enclosing Return[1,2]. >> (*Hold[Return[1, 2]]*) However, <...
3
votes
1answer
58 views

Why does syntax highlighting in `Set` and `Rule` not color pattern names on the RHS?

The mathematica front-end colors x on the right hand side of x_ :> x and f[x_] := x but ...
1
vote
1answer
39 views

Part function: can we use pattern for part functions? [duplicate]

Can we use some patterns for the arguments of Part functions? ...
6
votes
2answers
83 views

Association matching still not working perfectly?

Up until 10.4 you could not match on internal Association structure at all: http://mathematica.stackexchange.com/a/119542/6804 Now you can, but it seems flawed ...
0
votes
2answers
47 views

Can you unpack a list of values into variables in a With expression?

For instance, if I am trying to draw a graph with 5 vertices labeled a through e, and I want to draw edges connecting a and b, a and c, a and d, a and e, b and c, b and d, and c and e, I would run the ...
0
votes
1answer
43 views

How to use Set correctly

My codes are shown in the picture attached. I'm writing codes for numerical calculations frequently, and I think it looks neat and clear to organize input parameters in the form of table. For example,...
0
votes
0answers
40 views

Create a loop for assignment of Solve output [duplicate]

Is there a way to automatically assign the output of solve to a number of symbols? For example, assume that I have the solve statement as follows: ...
8
votes
2answers
70 views

How do I SetDelayed $Assumptions

For some reason, $Assumptions := (Print["y"]; x > 0) evaluates the RHS immediately. I have code in which $Assumptions ...
0
votes
0answers
21 views

How to make an expression in this case evaluated one step and stop there? [duplicate]

I wonder how to make Symbol@"m" evaluated once so that it becomes a symbol m which is ready to be assigned again. ...
1
vote
1answer
63 views

How to assign options to a variable?

I want to redefine a function similar to Plot like this: ...
2
votes
2answers
89 views
-1
votes
1answer
54 views

Iterate a large matrix calculation [closed]

I want to repeat the calculation of a pretty big formula about 100 times. I tried using Do loop but it takes sooo much time that mathematica stops working. I will take a simple example to illustrate ...
2
votes
1answer
58 views

How to determine where a variable got assigned a value?

I have a Mathematica notebook that includes some dynamic structures (with Manipulate). Sometimes, I discover that x has been ...
138
votes
2answers
6k views

What is the distinction between DownValues, UpValues, SubValues, and OwnValues?

When reading through the documentation, you often encounter the phrases DownValues, UpValues, ...
9
votes
0answers
69 views

Is there a way to TagSet a HoldAllComplete function?

Let's say I want to overload the built-in function Lookup, to handle my data wrapped in myObject. One would use ...
1
vote
1answer
139 views

Is there any way to implement a “sequential” With[] in Mathematica? [duplicate]

I want the equivalent of Scheme's let*, or basically, a sequential With that works like this: ...
9
votes
2answers
170 views

Passing an unevaluated part of an association to a function

I'm making a UI widget that controls sound volume on a speaker using a slider, e.g.: ...
10
votes
6answers
637 views

How do I randomly divide individuals into groups?

I would like to assign 'x' individuals to 'y' groups, randomly. For example, I would like to divide 50 individuals into 100 groups randomly. Of course, with more groups than individuals many of the ...
13
votes
1answer
214 views

Why can AppendTo modify a referenced list in-place but Part cannot?

Part, AppendTo, PrependTo, AddTo, etc. allow in-place modification of a list, but only Part requires that the list be referenced through a simple symbol, e.g. the following all does what you'ld expect:...
7
votes
1answer
323 views

How is LHS = RHS; … ; LHS (nontrivially) different from … ; RHS

I'm trying to understand how Mathematica thinks about the results of Set. Suppose we perform LHS = RHS. I'm focusing on when ...
0
votes
1answer
39 views

Where is the erroneous assignment that is causing my 'List of equations expected instead of tru' error?

I'm getting one those annoying 'NDSolve::deqn: List of equations is expected instead of True' errors. I have done everything I can think of to Remove and Clear all variables, including restarting ...
4
votes
2answers
78 views

Append fixed value to random selection of list

(This question might be an application of this other question, but there might be another solution specific to this application that I'm not aware of.) I am currently in a situation in which (in a <...
22
votes
3answers
496 views
2
votes
1answer
69 views

Writing my own error and warning messages

Question: How is message handling implemented in Mathematica when applying Set to unprotected global variables such as $TimeZone...
33
votes
1answer
743 views

How to augment the realm of functions Mathematica thinks it knows how to integrate symbolically

My question involves extending the functionality of Integrate over specific integrals in the most generic manner. Specifically, is it possible to "hack into" <...
0
votes
0answers
26 views

delayed assignment (:=) vs assignment (=) difference example [duplicate]

After reading through the documentation, I still do not understand the difference between delayed assignment (:=) vs assignment (=)? Can you give me some easy and simple examples? I am not very good ...
10
votes
3answers
189 views

Why is the first argument of the SetDelayed evaluated?

In[1]: f=g; In[2]: SetDelayed[f[x_],x^2]; In[3]: ?f Global`f f=g In[4]: ?g Global`g g[x_]:=x^2 However, SetDelayed has the ...
9
votes
4answers
415 views

Looping through 3 million elements of a list to 'Set' values is slow

I am looping through the 3 million elements of a time-series (v1, o1) and corresponding values (v2, o2). v1 contains a uniformly increasing timestamp (e.g. 1 to 3,000,000 in increments of 1) o1 ...
3
votes
1answer
77 views

Table generation with SetDelayed function [closed]

I would like to understand why the following two outputs differ: Let us define the following data set: ...
6
votes
2answers
122 views

Force evaluation of the right-hand side of a local variable definition

One can do expression = a + 1; f[a_] := Evaluate[expression] but how would one do something like this ...
4
votes
3answers
242 views

Using Block with a list of variables

I have a list of variables var={v1,v2}; which I want to protect/localize during a particular operation. I have decided that I want to use ...
5
votes
3answers
242 views

Turning an expression into a function inside another function

Say I have an expression g=Sin[q]; It is easy to turn it into a function, and to perform manipulations on this function (this and variants of this were discussed ...
1
vote
3answers
128 views

Setting ::usage for variables returned from a function

What is the best way to achieve {v,u} = f[]; (* Returns value and usage description *) v::usage = u; from inside f, i.e., <...
28
votes
3answers
443 views

Assign a randomly generated list to variable

Bug introduced in 10.0.0 and fixed in 10.0.2 I don't know if this is a silly question, but it really baffles me. So please help me understand this behavior. ...
8
votes
2answers
358 views

How to replace a variable that was assigned a value before

Question How to make the replacement $f[x] \to f[y]$ for an abitrary function $f$ if $x$ was assigned a value before? Example 1 How can I make the replacement $x +1 \to y + 1$ if I have assigned ...
0
votes
1answer
122 views

Variable dependency…easy one

I'm brand new to Mathematica...should be an easy one. Instead of writing u[x] everywhere in the code, how do I assign the dependency early on like this: u=u[x] ...
4
votes
2answers
131 views

Initializing several values of a function

How do I initialize several values of a function at once? Consider the function f[0] := 1; f[1] := 2; f[2] := 3; f[n_] := f[n] = f[n-1] + f[n-2] + f[n-3]; Is ...
2
votes
1answer
124 views

How to extract a variable names (not values) from a list of transformation rules?

I am trying to extract variable names from a list of transformation rules mapping = {var1 -> 'val1', var2 -> 'val2' }. Variables ...
9
votes
3answers
4k views

Assigning values to a list of variable names

As part of a calculation I need to do something like this Evaluate[{aaa, bbb, ccc}[[ index]]] = {1, 2, 3, 4, 5} so if index is ...
31
votes
1answer
1k views

How do you set attributes on SubValues?

SubValues, as discussed in a previous question, are declared as follows ...
9
votes
3answers
369 views

How to write a function-defining function which stores the function arguments in a stack?

I have a function-defining function SetAttributes[DefFn, HoldAll]; DefFn[f_[args___], body_] := f[args] := body; I am trying to modify this function to record ...
4
votes
2answers
162 views

Assignments in ParallelDo when using indexed variables

For convenience I use an indexed variables syntax to hold results of long computations for different integer parameters: ...
24
votes
1answer
514 views

Why does list assignment with a packed array result in unpacked values?

Bug introduced in 5.2 or earlier and fixed in 10.1.0 This is another question on the design choices in Mathematica. I understand that without direct reply from the developers it may not be ...