# Tagged Questions

Questions on assigning and unassigning definitions to names that represent them, including issues raised by context and localization. Use tag [assignment] for issues relating to Set versus SetDelayed.

207 views

### Representing a value in an output as a self defined variable

I'm trying to find a way to have Mathematica always represent a numerical value as a self defined variable that I define using lhs=rhs. For example, if I execute <...
283 views

### Distribute and analyze large datasets

I need to analyze very large datasets, and they obviously don't fit in a computer memory. I need to produce some statistics on these datasets, and this brings me here: How can I make some statistical ...
173 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] <...
119 views

### Maximum number of literal values for SetDelayed?

Under what circumstances should I expect Mathematica to turn a delayed assignment into an immediate assignment? I have put together a minimal example (available here) which demonstrates this behavior. ...
286 views

### Defining my own invisible operator

There are some invisible operators in Mathematica (\[ImplicitPlus],\[InvisibleTimes],...
1k views

### Table of Variables

I use a list of variables {x1, x2, x3} to Solve a particular set of equations. I am now trying to generalise this depending on ...
4k views

### Module with “local functions”

I am trying to use a Module having "local functions", i.e., those which I need to define only inside this module. So I tried this: ...
2k 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 ...
182 views

### Specifying optional arguments with variables

Perhaps this is poor programming on my part, but I would like to create a function that uses a variable as an optional parameter: var = 2; f[a_:var] := {a} The ...
225 views

### Can I redefine a list as a set of variables?

Suppose I have a list mydata = {3, 14, 15, 92, 65} and in some cases I want to manipulate it as a list, like for reading from and writing to a file, or for ...
597 views

### Using external variable as a variable inside WhenEvent & NDSolve

I'm trying to use the new WhenEvent functionality of NDSolve in Mathematica 9, in order to perform an action when a variable in the system reaches a certain value. I would like this variable to come ...
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 ...
203 views

### How can I define a ⊕ operator?

What is wrong with the following code? CirclePlus := SparseArray[Band[{1, 1}] -> {##}] & a_ ⊕ b_ := CirclePlus[a, b] SetDelayed::write: Tag Function in ...
364 views

### What does it mean when a function is defined with two pairs of brackets

I have noticed a function defined as such: f[x_][y_] := expr; How is the argument y in 2nd pair of brackets being used? What is the difference from defining a ...
188 views

### Injecting list of controls into manipulate

I am trying to program a method to manually move around graph vertices, and then output the new coordinates. I'd like to turn this into a function that can be called with a variable number of ...
339 views

### How to choose variables from a list for a function and then use the solution in a subsequent function?

I am trying to calculate heating degree days and cooling degree days and output that information to a table. I am using mathematica's curated data to do this. In text this is what I would like to do....
303 views

### Context “Unique to This Notebook” makes variables black even if they're not defined?

I'm trying to use this technique to keep variables separated between different notebooks. It seems to be working fine, except that variables turn black as soon as they are evaluated — any ideas why ...
1k views

### How to Clear variables with apostrophe?

An apostrophe ' is often used when we want to distinguish two variables. For example, if we already have a variable t and we may ...
228 views

I was using Needs["PlotLegends"] By chance I removed ShowLegend by Remove[ShowLegend] How do ...
107 views

### Naming conflicts with Dummy variables in several packages conflicts

I'm using several packages in a notebook. In each packages there is functions defined with dummy variables. When I load the several packages in my session, i've got a warning message: ...
100 views

### Creating functions from output of other calculations

Apologies in advance if the title is vague, I'm not really sure what to call this. I have a function (call it 'foo') that generates a largeish polynomial, and it is natural to make the variables be ...
203 views

### When to use indexed variables

Still learning the fundamentals of the language I would like to ask you what advantages there might be in writing something like: a[1] = 2; a[2] = 4; a[3] = "x"; ...
638 views

### Define a function with the condition that it must be positive

I have a function f(x) and I want to define a new function g(x) that is equal to f(x) only ...
9k views

### How to tell Mathematica that certain variables are real/imaginary, integer-valued, etc

I'm trying to expedite some quantum mechanical calculations by running them through Mathematica. Expectation values and stuff like that. When I say, for example, ...
522 views

### Proper use of arbitrary number of variables

So, I'm working on a project where the number of independent variables is not fixed. Consider a problem of $N$ independent variables, $\boldsymbol{r}$. I want to perform different things with them. ...
158 views

### Proper localization of variable names

In functions like NonlinearModelFit I need to specify parameters with a symbol name. If I localize these parameters they get cluttered in the output (e.g....
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 ...
303 views

### How can I define variables that follow a naming pattern?

Let's say I have this enormous list of a million elements, and I want to access this list piecemeal in non-intersecting sublists of length ten. If ...
167 views

### Put local variables for Block in a variable [duplicate]

Is is possible to assign {x = 2, y = 3, z = 4} to a variable var so that one can write ...
206 views

### Forcing Mathematica to recognize a symbol without defining it

In the Mathematica front-end, symbols that have been defined are colored black and symbols with no definition associated are colored blue. This is useful to prevent spelling mistakes. Also, defined ...
2k views

### How to create a Table of Tables with indexed variables

I want to use concise code to generate a table of values that list the addition of a set of vectors. What I am looking for is essentially a Table of Tables. I will show here the kind of lists I want, ...
140 views

### How do I constrain variables to a user-defined domain in ArgMax?

I am trying to ArgMax a function over x, but x is only defined between ...
160 views

### Multiple down-values with exactly the same lefthand side

I was working on an answer to this question, when I was sidetracked by what I bring up here. I wanted a function, which when given a string representing a binary number, would convert the string to a ...
6k views

### setting a variable equal to the output of FindRoot

So I set a function f[x] f[x_] := x*E^(-x) - 0.16064 Then I set a variable 'actualroot' to the function FindRoot, starting at 3 ...
65 views

I have: ...
229 views

### How can I overload a function with multiple bracket-slots so f[a][b] and f[a] can coexist?

Maybe this is not even possible: I want to create a function f that can have two input brackets like: f[a_][b_:1]:= a*b and ...
128 views

### Defining a function that prints both the name and value of a variable defined locally within the calling function

To save time when debugging with Print statements, I'd like to define a function -- call it PrintVal -- that prints both the name and value of a variable defined locally within the calling function. ...
88 views

### Using an external Pattern breaks Format

I noted while writing this answer that using an external Pattern on Format doesn't work: ...
111 views

### What's reliable way of finding declared but undefined functions/symbols in several interrelated packages?

I have many packages some of which use some of others. I have many symbols defined in them. Is there a reliable way of finding declared/exported but undefined functions/symbols in several ...
2k views

### Global variable initialization in packages

Is it a good idea to Initialize variables globally inside a package ? will they be local by default to that package ?
257 views

### Mathematica does not understand (R^3)^(1/3) is the same as R [closed]

In the output from a calculation in mathematica stands a/((R^3*c)^(1/3)), with c and a ...
355 views

### Can I create a dynamic number of rows in TabView through an iteration?

I have written code, with the help of stackoverflow of course, and I want to make it user friendly so that other people in my lab can use it. I'm playing with DialogCreate and similar functions. I ...
140 views

### Using a variable to tell Mathematica which existing variable to manipulate

I have an estimation routine I have coded up, I want now to do some tests on it where I pick a particular parameter and run the estimation for differing values of that parameter. What I want is to be ...
443 views

### How to declare a function that uses local variables of a module outside this module?

I have the following code Module[{f,x=0}, f[t_] := x + t; ..........; ...f[1]...; ..........; ] My aim is to put the declaration of the function ...
2k views

### How to linearize an expression automatically?

I would like to automatically linearize some long equations in the scope of variational calculus. Here follows an example of what I need to do : Given two variables $a_1 = q_1 + \delta q_1$ and \$a_2 ...
112 views

### Module, local variable

Lets say I define a Module, that internally use iterating in a Table or Do, say something ...
110 views

### Sections with unidirectionally shared variables

I have 2 sections is my notebook: ...
254 views

### Renaming a list with name obtained interactively

I have a list say: m = {1, 2, 3} The list is inside a package, and is the result of a calculation. I want to give the user the option to rename it, for example ...