Questions tagged [variable-definitions]

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.

Questions on assigning and unassigning various definitions to objects/symbols that represent them, including issues raised by context and localization.

Use tag for issues relating to Set versus SetDelayed. See also for unassigning expressions from the names that represent them.

Useful links:

507 questions
25
votes
1 answer

What is $ sign in Mathematica?

Is it a special sign or it can be used as anything else? For creating variables for example. $x=4
Misery
  • 2,640
  • 1
  • 30
  • 39
22
votes
2 answers

How to define a global variable when giving each notebook its own Context?

I have restricted the context of my notebooks to each individual notebook. So variables in each notebook are local and are not seen in another notebook. But in two of my notebooks I have two functions that I want to plot simultaneously with the…
MOON
  • 3,864
  • 23
  • 49
14
votes
7 answers

Using a built-in symbol as a variable

I want to produce a Mathematica Computable Document in which N appears as a variable in my formulae. But N is a reserved word in the Mathematica language. Is there a way round this other than using a different symbol? It seems a severe limitation if…
Marc Widdowson
  • 141
  • 1
  • 3
13
votes
3 answers

Variable variable names

I have two variables, $ u \in \{0,40\}$ and $\gamma \in \{0,1\}$. I take $10$ values of $u$ and $5$ values of $\gamma$ and using their combinations as a pair of input parameters, I perform some mathematical operations a total of $10*5 =50$ times.…
Amatya
  • 6,888
  • 3
  • 26
  • 35
10
votes
3 answers

Protecting function definitions only for particular inputs

I would like to be able to define the values of a particular function for new inputs. f[x1]=f1; f[x2]=f2; I would also like to be able redefine the values for most inputs. f[x1]=f3; f[x2]=f0; But there are certain definitions I would like to…
Timothy Wofford
  • 3,803
  • 2
  • 19
  • 24
9
votes
2 answers

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 ?
santhosh
  • 423
  • 3
  • 7
9
votes
1 answer

Finding a variable name given its numerical value

If I set up a = 1 Is there any command to get "a" by typing value 1? Another example. If x = 3 y = 7 z = 6 then, Can I get 'xyz' by typing something like {3,7,6}?
S. Lee
  • 91
  • 1
7
votes
2 answers

Copy a function instead of referencing

Is there an option to let me assign the old function of f to g, without changing g when reassigning f? This piece of code describes my problem: f[x_] := x^2 f[2] (*Output: 4*) g = f g[2] (*Output: 4*) f[x_] := x^3 f[2] (*Output: 8*) g[2]…
Tobias
  • 563
  • 2
  • 7
7
votes
4 answers

Put local variables for Block in a variable

Is is possible to assign {x = 2, y = 3, z = 4} to a variable var so that one can write Block[var, x*y*z] (or similar) instead of Block[{x = 2, y = 3, z = 4}, x*y*z] ?
u17
  • 601
  • 3
  • 8
7
votes
3 answers

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 want define another variable t'. What I found weird is that, in *Mathematica` it is legitimate to define a variable with…
matheorem
  • 17,132
  • 8
  • 45
  • 115
7
votes
1 answer

How to define a real positive variable in mathematica

Suppose I have a function $f(x)$. I want Mathematica to treat $x$ as a real positive number, and hence to interpret $\sqrt{x^{2}}$ as $x$, for instance. How to do that?
John Taylor
  • 5,701
  • 2
  • 12
  • 33
7
votes
1 answer

`Quit` vs `ClearAll["Global`*"]`

Quit erases all the definitions (by quitting the kernel), but so does ClearAll["Global`*"] (or other contexts). What's the difference in terms of variables in the notebook?
Al Guy
  • 1,610
  • 1
  • 10
  • 15
6
votes
2 answers

Confusing behavior when passing a variable vs. inlining a function call

Newbie question here. Consider the following two functions: f1[n_] := ( q = {0, 0}; Do[q[[RandomInteger[{1, 2}]]] += 1, n]; Return[q] ) f2[n_] := ( q = {0, 0}; Do[k = RandomInteger[{1, 2}]; q[[k]] += 1, n]; Return[q] ) Both seem to…
6
votes
2 answers

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 operations to be applied to all members. But I also want to access each member…
stevenvh
  • 6,866
  • 5
  • 41
  • 64
5
votes
1 answer

How to define a variable as a function of another variable?

I want to define a variable q which is a function of t. And I want to define another variable qdot = dq/dt. Then what I want to archive is that if I have a function f = a*Sin[q], and when I take the derivative df = D[f,t], Mathematica…
auzn
  • 225
  • 1
  • 5
1
2 3 4