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
0
votes
0answers
184 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
76 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
153 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
179 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
118 views
8
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
254 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
228 views
13
votes
1answer
301 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
52 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
734 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
61 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
479 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
298 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
14k 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 ...
0
votes
1answer
92 views

Using a[i] as variables

I am using variables of the form $a[i]$, e.g. $(a[1],a[2],a[3],...)$. When I pass them to a function I need to determine which one they are, in other words, what the value of $i$ is. Specifically, I ...
6
votes
1answer
164 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 ...
0
votes
1answer
58 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 ...
2
votes
0answers
501 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 ...
9
votes
2answers
874 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 ...
2
votes
2answers
1k 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
231 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
1answer
123 views
9
votes
1answer
298 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
80 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 ...
0
votes
1answer
30 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
35 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 ...
3
votes
1answer
5k 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
91 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 ...
3
votes
0answers
84 views
4
votes
2answers
350 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 ...
1
vote
2answers
66 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 ...
3
votes
1answer
93 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 ...
1
vote
1answer
54 views
9
votes
3answers
751 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 ...
14
votes
4answers
2k 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 ...
2
votes
1answer
1k 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
122 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 ...
6
votes
1answer
140 views
2
votes
1answer
308 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
257 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
116 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
106 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)...
1
vote
2answers
480 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
174 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
766 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 ...

1
3 4
5
6 7
9