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.

Filter by
Sorted by
Tagged with
14
votes
4answers
4k views

Refering to global variables inside modules

How do I refer to global variables inside modules if the same name is used for a local one? In code, I want that ...
27
votes
1answer
10k 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: ...
2
votes
1answer
169 views

Why is my variable Lambda defined but not the others?

I would like to understand why in the following code, my variable Λ is recognized by the system but not n. In fact for me ...
0
votes
1answer
71 views

Using Subscripted Notation without Introducing new identifier

I would like to use subscripted notation such as $\sigma_x$ as identifiers for use as variables. In this example I am using the Pauli Matrices so that I would use notation such as: $$ \sigma_x = \{\{...
2
votes
1answer
4k views

Constructing variable names from a string

I have groups of descriptive variable names and dont want to write explicit code for each group, e.g. (and this is a contrived simplification) ...
1
vote
1answer
559 views

Plot 3D doesn't show anything

Good Evening, I defined a function which is composed of other several functions. Mathematica compiles well but I can't get a plot and I do not understand way. Can anyone help me with the code and ...
9
votes
1answer
366 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 ...
24
votes
3answers
618 views

Why x = x doesn't cause an infinite loop, but f[x_] := f[x] does?

If I execute: In[1] := x = x Out[1] = x and then I evaluate the symbol x: ...
3
votes
0answers
61 views

Variable assignment/replacement issues

I have three questions about variable assignment. Module[{z}, z = y; p'[y] /. p -> Function[y, Evaluate[z]]] When I run the above code, it outputs 0. 1) If I ...
3
votes
2answers
70 views

ClearAll except a data table

How can I ClearAll variables and tables, except a table of data? Suppose the data table is WRR. ...
4
votes
1answer
266 views

Define scalar quantity that squares to 1?

My equations contain different cases which differ only by some signs. So in order to work with all cases simultaneously, I introduce a placeholder for a sign: s[x] ...
4
votes
1answer
231 views

An interesting function: Plot f[x] != Plot f[y]

Let's consider this function f[a_] := x^2 /. FindMinimum[-a x^2 + x^4, {x, 1}][[2]] Why the output of the following two Plot ...
0
votes
1answer
97 views

Set does not work

I tried following code, but it does not work as expected: Do[Set[a[[1]],a[[2]]],{a,{x->2,y->5,z->x+y}}] {x,y,z} I ...
4
votes
2answers
94 views

f = p; p = 2; How to clear the value of p without explicitly writing the variable p in the code?

I had a problem on a program of mine that I could avoid by developing the code through other ways. On the other hand, I still do not know how to solve the simple problem below: Consider these two ...
1
vote
1answer
33 views

Substituting variables in only certain environments? [duplicate]

I was integrating a function and got something essentially like E^(mu beta) * (1/beta) There beta is defined as ...
0
votes
0answers
66 views

Why 3 Different results for same Integral of a series?

I have the integral of a Series. According to some details, I get different outputs and I don't know which to rely on. Can anyone explain me the differences and if I am doing some mistakes? ...
0
votes
2answers
727 views

Evaluating Series at a point not working [closed]

I have a series as an output and I am trying to plot it and/or evaluate it. How come that doesn't work? I get: Attempt to evaluate a series at the number 0.10001838571428572`. Returning ...
0
votes
0answers
85 views

Why do I get Imaginary unit after Abs and Complex expand?

I am getting an imaginary unit in the output after Abs and saying Complex Expand, why? Then, when I integrate in x and z, I miss beta. I don't get why beta vanishes in the definite integral. ...
0
votes
0answers
390 views

Colors of variable mathematica

Suppose that I have an equation which goes like this: x = 2; yp = 2; y_p= 2; a = x + yp + y_p; Usually, once the variable is defined it will be of blue color and ...
0
votes
0answers
318 views

Defining a del operator [duplicate]

I understand the Grad function is a mean to taking the gradient of an arbitrary function. However, I'd like to define the Del ...
4
votes
1answer
94 views

Definition pattern

If you make a definition, for example blah := RandomChoice[{1, 1, 1, 1, 1} -> {1000, 1001, 1002, 1003,1004}] is there any way to programmatically use ...
17
votes
5answers
4k views

Preventing Superscript from being interpreted as Power when using Ctrl+^ shortcut?

I have very strong desire to use superscript as the index of the variable. However, it looks like that the Mathematica automatically recognize the superscript as the power and I got message that my ...
23
votes
4answers
2k views

Elegant manipulation of the variables list

I have a list of global variables (some of them are indexed variables), for example: varsH = Hold[U0[1], U0[2], B0, V0[1], V0[2]] Or (if it is easier to handle) ...
32
votes
2answers
1k views

How to make Mathematica variables declarative instead of just-in-time?

Is there a way to have Mathematica at the notebook level (SetOptions[EvaluationNotebook[], CellContext -> Notebook]) only uses a set of declared variables in the ...
19
votes
8answers
2k views

How to Set parts of indexed lists?

I would like to assign a list to an indexed variable and then change it using Part and Set like this: ...
1
vote
1answer
101 views

Is it possible to "escape" numbers so they can be used as a variable name? [closed]

I would like to be able to use numbers in the names of some of my variables, it's simply easier to read that typing TwoPointZero. Is this possible? Or is there an alternative to being able to define ...
3
votes
2answers
92 views

Find the input definition

Consider the following definition a = D[x,x] Now, a=1. Is there a way in which I can recover the information about the input ...
1
vote
2answers
683 views

Solving recurrent function with 2 variables

My understanding of Mathematica is very limited since I just started using it, I would appreciate any feed back or help. I am trying to find the closed form of a recurrent function with 2 variables: ...
4
votes
1answer
229 views

Specify Variable Size

Is there an easy way to specify the variable size and still use them as variables more specifically for the .NETLink? Something like the following I am thinking. ...
0
votes
0answers
71 views

Using sub-scripted variables in functions

Is it possible to use subscripts in Mathematica functions, for example f[Subscript[x, a] _] := x^2 However this doesn't seem to work, is there a way to allow ...
0
votes
2answers
130 views

Merging two variables in one

I was looking for a way of, given two variables called A and B, obtaining a new variable called AB. My idea was doing simple pattern matching, e.g. ...
0
votes
0answers
185 views

How can I cleanly distribute definitions of system functions?

I have a package that redefines a system symbol, and I am struggling to find a clean solution that will ensure that those redefinitions will still work inside a parallelized environment. The core ...
0
votes
0answers
72 views

Is it possible to define a new built-in function in Mathematica? [duplicate]

Say I want to define a function to do integration by part, is it possible to define it as a new built-in function in Mathematica, so that I don't need to define it every time I want to use it?
3
votes
1answer
77 views

Variable not available in kernel despite `DistributeDefinitions`

I am following this answer to evaluate certain cells in a separate kernel. I have created a separate kernel called K2 and have the following MWE: ...
0
votes
1answer
165 views

Define new symbols and "inverse" function

I have an expression that involve variables and conjugate of the variables eg ...
20
votes
3answers
1k views

Variable scope similar to other languages

Mathematica, unlike many other languages, defines the variables in the global scope unless it is explicitly asked to define a variable in a local scope, e.g., using ...
3
votes
1answer
219 views

Transformation of variables in function in mathematica

How do i change variables of function in mathematica ? for example of f(p,q) = p^3 + q^3, from p,q to x= p-q and y = p+q, so that the function now becomes f(x,y) ?
3
votes
2answers
126 views
9
votes
1answer
1k views

Difference between variables and functions

Forgive me if this question is very basic; I've learned Mathematica mostly by example. In most programming languages, there is a clear distinction between variables and functions: variables hold ...
3
votes
1answer
282 views

Is it safe to assign a variable and function of the same name for different things?

I'm writing out a notebook that goes through the van der Waals Equation of State for gases, and I run into a situation where I want to assign (simplified) Tc[b_]:=5b, use that to solve for b in terms ...
1
vote
0answers
249 views
13
votes
1answer
310 views

Working with DynamicModule: SetDelayed + OwnValues

Shortly, definitions in form of e.g. x:= RandomReal[] have to be avoided inside DynamicModule[{x}, ...]. Why?, this ...
0
votes
0answers
54 views

Naming variables from other variables

I'm inside a Do loop and I'm constructing a Dataset. I have consumers that come each period and I need a unique identifier for each of the consumer. To uniquely identify a consumer I need 3 variables:...
8
votes
2answers
793 views

How to Clear variables represented as a list of strings?

Say I have a string list called fullpara fullpara={"width", "long", "line", "distance"} And there are corresponding variables ...
0
votes
2answers
62 views

representing external function using variable inside a function

Suppose I have a matrix mat[a_,b_,c_,w0_,y0_][omega_,ak_]:={ {I TMM[a,b,c][omega,ak]w0, -I TMP[a,b,c][omega,ak]}, {TMP[a,b,c]y0, I TMM[a,b,c]w0 y0}} Now the ...
1
vote
1answer
639 views

How do I conditionally (or temporarily) assign a numeric value to a variable [closed]

I've used TI's CAS system quite a bit, and I have a nice pattern for evaluating expressions without setting and then later clearing a variable. For example, on my TI-89, I can do the following: $-\...
14
votes
7answers
3k views

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 ...
1
vote
0answers
45 views

How to define function that variable is optional? [closed]

I want to define some function that I can do something for the troubleshooting purpose. ...
12
votes
3answers
305 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 ...
10
votes
1answer
15k views

Setting a variable equal to the output of FindRoot [duplicate]

I define a function $f(x)$ as f[x_] := x*Exp[-x] - 0.16064; Then I set a variable actualroot to the function ...

1
3 4
5
6 7
9