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.

learn more… | top users | synonyms

12
votes
1answer
97 views

Working with DynamicModule: SetDelayed + OwnValues

Shortly, definitions in form of e.g. x:= RandomReal[] have to be avoided inside DynamicModule[{x}, ...]. Why?, this ...
5
votes
1answer
141 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 ...
-3
votes
0answers
37 views
0
votes
1answer
47 views

How to erase definition introduced by using Set instead of Equal in Solve [duplicate]

When trying to solve a set of equations, I made a mistake by using = instead of ==. Now when I fixed the mistake, the equation ...
1
vote
0answers
45 views

How to declare variables with plus/minus sign as subscript/superscript?

I am pretty new to mathematica, so please forgive me if I ask any stupid questions. I want to create a vector $a^{+}=[a^+_{k-2},a^+_{k-1},a^+_{k},a^+_{k+1},a^+_{k+2}]$ and then do some symbolic ...
0
votes
0answers
144 views

How can I define a derivative with respect to implicit parameterized variables?

I know how to define derivatives for explicit single variables: Derivative[n_, 1][p][x_, v_] := D[p[x, v], {x, n + 2}]/2; D[p[x, v], {x, 3}, {v, 4}] Output: $\...
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 ...
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 ...
9
votes
1answer
190 views

How do I insert OwnValues inside a held expression without evaluating it?

Here is a very long and complicated expression, which we abbreviate as a. I store it using SetDelayed because I want to perform ...
0
votes
0answers
21 views

domain of an input variable

Suppose I have a function called Exercise which is called in this way: Exercise[Gamma[x]+x*n,x] How can I indicate that n is a positive integer?
8
votes
1answer
198 views

Why does the global variable exist here, where it was declared only in Module?

Why does Mathematica choose the mechanism that makes the global variable a here while parsing? In ...
0
votes
1answer
31 views

This vector definition with index in subscript is incorrect [closed]

I am trying to define a vector of values. Here is an example n = 8; Table[Subscript[ω, i], {i, 1, n - 1}] = Table[Sqrt[2], {i, 1, n - 1}] Yet this leaves me ...
7
votes
2answers
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: ...
0
votes
1answer
29 views

Series Soln False error [closed]

When I try to define my equation : sys3 = {y'[x] == 2 y[x]/(1 + y[x]^2) - Exp[y[x]]/(1 + Exp[y[x]]), y (0) == 1} OR ...
1
vote
0answers
33 views

How to define a variable describing several options? [duplicate]

Plot[y=x, {x, -1, 1}, PlotPoints -> 24, MaxRecursion -> 0, ColorFunctionScaling -> False, BoundaryStyle -> None, MaxRecursion -> 0] I will ...
1
vote
1answer
84 views

`Quit` vs `ClearAll[“Global`*”]`

Quit erases all the definitions (by quitting the kernel), but so does ClearAll["Global`*"] (or other contexts). What's the ...
1
vote
1answer
69 views

How to extract all necessarily code for a function?

Many times when someone pastes a piece of code into SE there are missing values and symbols that the user left out. To prevent this I'm looking for a function that uproots other functions (extract ...
8
votes
2answers
536 views

Character to replace _ in symbol names?

In C, _ comes in handy when naming variables and functions, as a replacement for space. For example: ...
4
votes
2answers
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 ...
27
votes
5answers
3k views

how to differentiate formally?

I have been wrapping my head around this for a while now and I have not found a solution so far. I want to work with an arbitrary number of variables in mathematica and use some built in functions. ...
1
vote
2answers
54 views

How do I tell if a function definition “contains” a symbolic expression?

Consider a definition like f[x_] := x[[1]] + x[[3]] + x[[1 + 2]] I want a "ContainsExpression" which I can use similarly to ...
153
votes
7answers
7k views

What are the use cases for different scoping constructs?

Mathematica includes three functions that I know of which can be used to effectively (if not actually) define a variable and give it a value within a local scope: ...
3
votes
1answer
74 views

plotting after solve does not display anything

I'm quite new to Mathematica language, I am trying to figure out where I am making mistakes in Plotting a specific function that depends to other variables: I want to plot ...
9
votes
3answers
455 views

Why doesn't DumpSave work for elements created within a local notebook context?

I recently noticed that when dealing with notebooks with local context, I cannot successfully DumpSave variables, or, rather, when I call ...
18
votes
5answers
492 views

How can one manually change the rule ordering

I have a function which has some general behaviour, but that should act on some specific kinds of objects in some other way. I know that Mathematica is supposed to automatically order the rules so ...
11
votes
4answers
923 views

Subscripts - Why do I see the error “only assignments to symbols are allowed” when using a Module and not otherwise?

When I type Remove["Global`*"] foo[] := Module[{Subscript[a, 1] = "x"}, 0]; foo[] I get the expected error "only assignments to symbols are allowed". I ...
1
vote
1answer
49 views

How to unshadow a chosen definition for a function

I want to use the package NCAlgebra. However after successfully installing the package and trying to write some code, basic functions like SetNonCommutative[...] ...
2
votes
3answers
74 views

How to make a list (of data points) whose name is the same as the file name from which the data is imported [duplicate]

I have a set of files, e.g. file1.dat, file2.dat,... containing data (list of data points to plot, manipulate...) I want to do the following ...
2
votes
1answer
106 views

Clearing a global variable from inside a Module

This is a highly simplified version of a initialization problem I have with a complicated program with many (about 100) modules. If one enters: X=42; Clear[X]; the ...
1
vote
5answers
179 views

Do not expand matrices in Mathematica calculation

Here is an example of a problem I'm having. Consider that I have defined: omega={{p[t]},{q[t]},{r[t]}} x={{a},{b},{c}} R={{1,2,3},{4,5,6},{7,8,d}} What I would ...
1
vote
0answers
78 views

Coupled ODEs with boundary conditions - DSolve Error [closed]

I'm relatively new to mathematica and I can't find the error here. I suspect it has something to do with the fact that vx, vy, vz aren't blue on my mathematica - as in, they already have some assigned ...
1
vote
1answer
75 views

Variables input generation for Minimization in High dimensional space [duplicate]

I'm currently doing optimization in a high dimensional space. I was thinking of giving FindMinimum (or NMinimize not certain yet)...
43
votes
5answers
22k views

How do I clear all user defined symbols?

Is there some way to do this other than going to Evaluation -> Quit kernel and firing a new one up?
1
vote
2answers
356 views

TabView: Reset some dynamic variable on tab selection

Given a TabView panel like this one TabView[{ DynamicModule[{x = False}, {Checkbox[Dynamic[x]], Dynamic[x]}], "foo"}] I ...
2
votes
0answers
48 views

Share variables among notebooks with different Kernels

So I have a server running in another notebook with a secondary kernel. I run my main notebook and launch the server notebook, but I have configured the variables in my main one, and can't find a way ...
6
votes
1answer
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 ...
2
votes
0answers
60 views

Changing variables in a series expansion

I want to compute the Taylor expansion of some pure function f[x_], but then perform a change of variables in the resulting expression. So, for example, the output ...
1
vote
0answers
68 views

Binding a variable to an unbound variable [closed]

I'm trying to do something like the following: (minimal example, f2 unbound) ...
3
votes
1answer
59 views

Setting a One Dimensional Function Equal to a Constant over a Specific Range

I am trying to take the output from NDSolve and create a variable equal to the solution except for a certain range of values. Here is the code I am trying to use ...
0
votes
1answer
82 views

How to implement the for loop to replace text strings or texts?

I wonder define a bunch variables named like $X_1$, $X_2$, $...$, $X_n$. Is there some smart way to declare them instead of by pure typing. One trick I can image is to use the for loop,...
2
votes
0answers
61 views

Follow-up to “How to differentiate formally?”: Efficiency concern

In link to "how to differentiate formally?" and particularly to the answer by @Jens, I want to do something like this: ...
1
vote
1answer
109 views

Converting the subscript of matrix name to a variable

I want to change indices of matrix name during loop for creating different matrices. For example; ...
3
votes
2answers
112 views

Module, local variable

Lets say I define a Module, that internally use iterating in a Table or Do, say something ...
1
vote
1answer
57 views

Create a list of variables of a function

How can I create a list of variables of simple functions with arguments? These functions will be defined by the user, to be manipulated with some code later. ...
2
votes
1answer
47 views

Definition of a function depending on a sequence

let $a_{n}$ is a given fixed sequence, say $a_{n}:=1/n$. I would like to define something like $$D_{j}:=\sum_{k=1}^{j}\frac{1}{j!}BellY[j,k,\{a_1,a_2,\dots,a_{j-k+1}\}].$$ Function BellY is ...