# Tagged Questions

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

25k 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?
6k views

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

When reading through the documentation, you often encounter the phrases DownValues, UpValues, ...
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 ...
969 views

### How do you set attributes on SubValues?

SubValues, as discussed in a previous question, are declared as follows ...
2k views

### How to pass a symbol name to a function with any of the Hold attributes?

Given a function with the attribute HoldFirst, HoldAll or similar, and a variable, list, how ...
1k views

### Scoping in assigning a derivative

While answering another question, I stumbled upon a problem I cannot easily resolve. To assign the derivative of a function to another function, typically one can do this with a ...
474 views

### Nested definition: How can I define a function with a passed-in expression?

Here's a simplified version of what I'm trying to do: ...
645 views

### Reassign values to symbols

I've got a situation where I have, say 4 symbols, a, b, c and ...
363 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 ...
308 views

### How to make a function like Set, but with a Block construct for the pattern names

How can we define a function that works like f[x_]=ComputeSomething[x] and treats x as a variable that does not have a value? ...
505 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 ...
426 views

### MapThread gives different results from ToExpression when trying to assign variables from a list

I have the following data set: data = {{"Jakarta","Surabaya","Bandung"},{1,2,3}} and I'd actually like to assign the numerical values to the categorical data so ...
1k views

### How to implement the Observer design pattern?

As a programmer with a history with procedural languages, the Observer design pattern inmediately springs to my mind when attacking certain class of problems, mostly UI/notifications related. A ...
176 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 ...
646 views

### Delayed evaluation of assignment

I have a set of PDE's that depend on parameters. They depend on many parameters, but for simplicity we can here assume that they depend only on one, say a. I want ...
215 views

### why set values in this way doesn't work?

question is as follows define a list ttt={1,2}; and if I set values in this way {ttt[[1]],ttt[[2]]}={3,4} then the value ...
602 views

### Does Set vs. SetDelayed have any effect after the definition was done?

I was always assuming that the only difference between Set (=) and SetDelayed (...
1k views

### Assign output of solve to variables [duplicate]

I have this input: Solve[x^2 + 3 x + 2 == 0, x] which gives this output: {{x -> -2}, {x -> -1}} I want the first x ...
726 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" ...
416 views

### Triggering actions when a variable is set

Some built-in variables trigger actions when their values are changed: ...
341 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 ...
186 views

### Associate the elements of a table

I have a table form as: table = {{a, 6}, {b, ff}, {c, 2}} I want to associate the first element of each pair from the table to the second element of the pair as ...
321 views

### Setting parts of a list

Suppose I have list a = Range[10] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} in which I want to set some elements to be a list ...
438 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. ...
156 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.: ...
169 views

### Different behaviours of Default Argument

I don't really understand the behaviour of Default Argument. If I execute this command in Mathematica: In: {f[a], f[a + b]} /. f[x_ + y_.] -> p[x, y] ...
235 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 ...
317 views

### Altering values in Manipulate with dynamically generated controls

I have a Manipulate whose controls are generated based on a parameter in a containing Manipulate: ...
184 views

### direct assignment to the element in a Table

I have already asked a related question here why set values in this way doesn't work? But I think I have to write the question which I encountered explicitly? ...
157 views

### Few quick Mathematica questions about Dictionary

a. Get the list whose elements are of the form {language,number of words in dictionary) I tried this, and it gave me the number if words in dictionary, but I don't know how to get the language part: ...
222 views

### Clearing a specific definition

Consider the case where a symbol has multiple definitions attached to it, a /: Subscript[a,2] := 1 a[b_] := 2 a[b_, c_] := 3 How does one clear (/unset/remove) ...
1k views

### How can I randomly generate a unique, unused symbol?

In a previous question on collecting terms for a multivariable polynomial, I answered with a solution that required a unused symbol to be used for a temporary substitution and back substitution. It ...
293 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 ...
328 views

### Assign variables automatically to a function

Lets consider that I've this function: fn = a*x^2 + b*x + c; The idea here is to assign automatically the variables a, ...
135 views

### DownValue assignment using Apply

Why does assigning a DownValue using Apply, e.g., ...
302 views

### How to ignore list elements when extracting with pattern matching

If I have a simple list, say {1, 2, 3}, and I want to extract a subset of the elements, what is the correct syntax? e.g. { i, _, j } = {1, 2, 3} I want i = 1 ...
196 views

My code: ...
354 views

### Implementing key-value associations in Mathematica 9 with inexact numbers for keys

I'm not sure of what type of problem my issue falls into, so I haven't been able to search forums with any success. If this has already been solved then my apologies! Essentially I'm trying to set a ...
1k views

### Clear and Unset doesn't free memory

Example: Try this example only if you have > 4G ram d = 2000; f[x_, y_, d_] = Sum[Subscript[a, i, j]*x^i*y^j, {i, 0, d - 1}, {j, 0, d - i}]; Then ...
94 views

### Problem with Simplify, Sqrt, and Set: What's going on?

I am having some trouble getting Mathematica to simplify an expression of the form Sqrt[x]*Sqrt[1/x], where x>0. The problem is that x is assigned to some complicated form by the time Mathematica ...
1k views

### How to store value in a For loop

I am using two For loops. When the inner loop finishes, I don't want to print but I want to store the result from the inner loop in some variable so that I can call ...
164 views

### Bare symbol invocation fails but not if used with an argument

How to achieve the following behavior on a symbol f? Background: The main goal is to use the symbol to tag an abstract data structure where downvalues are used to store information. Only defined ...
159 views

### Unset while running recursion

I am trying to run a recursive definition while at the same time clearing previously found values, so my memory is not completely consumed. I found this: How to clear parts of a memoized function? ...
104 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: ...
87 views

### Assigning to the “local” version of a symbol

Compare Manipulate[c[1] = 1; c[1], {c[1], 0, 1}] with Manipulate[Do[c[i] = 1, {i, 1}]; c[1], {c[1], 0, 1}] The first case ...