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.
1
vote
2answers
98 views
Add a letter to a variable name from a list
Basically I am searching for a way to add the letter u to an existing list of variables {a,b,c,d} to obtain the variable list ...
0
votes
1answer
26 views
Collecting variables from Subscript
I have followings set:
t = Transpose[{x[#] & /@ Range[20], RandomInteger[15, 20]}];
Subscript[#[[1]], #[[2]]] & /@ t
The code is just to build my set.So ...
2
votes
2answers
64 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 ...
2
votes
1answer
57 views
What is the need for function parameters? Many possible inputs
If I have many possible variables related to one another, why do I need to define my function with parameters for plotting? For example, if I have an equation like:
...
3
votes
1answer
56 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 ...
2
votes
5answers
168 views
Treat list as cyclic
I am considering the following case. Say that T={p1,p2,p3} represents a triangle. In addition, I want to parameterize the edges of the triangle ...
1
vote
0answers
58 views
How to assign (and retrieve) variables with subscripts? [duplicate]
I like to give subscripts to my variable names when the variables are related. I.e.,
Subscript[r, i] = 3
3
A problem arises when I later assign ...
1
vote
3answers
77 views
Declare local variable when defining a function to mimic Table[]
The problem:
I want to define a function tab to replace the long line
Table[f[i,j,k,l],{i,3},{j,3},{k,3},{l,3}]
by a shorter ...
1
vote
3answers
82 views
How can I prevent Superscript from being interpreted as Power?
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 ...
2
votes
2answers
61 views
Extracting variables from Hold expression
For example I have some global assignments x=1;y=2;z=3 and an expression Hold[x*y/z]. How can I now extract variables ...
3
votes
2answers
137 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 ...
5
votes
3answers
110 views
Obtaining the name of a variable as a string
Suppose that I have an arbitrary variable myVariable. Is there some function fun -- either built-in or one that I can define -- ...
8
votes
3answers
120 views
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 ...
18
votes
2answers
262 views
The dangers of SaveDefinitions — should this really happen?
I have been bitten hard by SaveDefinitions -> True. I'll describe in detail what happened below.
My questions are: Is this a bug? What is the most convenient ...
1
vote
1answer
88 views
Print indexed (by subscript) variable name systematically
I have some variables : Subscript[S, 1], Subscript[S, 2]...etc.
But they are defined in a for loop like For[g = 1, g < 4, g++, Subscript[S, g] = g];
Later, I ...
7
votes
3answers
189 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 ...
2
votes
1answer
77 views
Reuse local variable in declaration within With [duplicate]
Considering the richness of Mathematica.SE, I am quite surprised I could not find my answer... I am very sorry if it is a duplicate.
Consider the following example:
...
0
votes
1answer
60 views
Arbitrary number of variables in Module, Block, etc
How do I specify an arbitrary number of variable names and initialize them inside of a Module or Block?
For example, I want to do something like:
...
0
votes
0answers
77 views
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 ...
-2
votes
2answers
135 views
Mathematica not assigning variable correctly
So I have been fiddling with this the last hour and I just can't get it to work.
I have 3 matrices of the same size which contain nothing but 0's in a list, I also have 3 matrices of the same size ...
3
votes
3answers
113 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 ...
7
votes
1answer
122 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 ...
1
vote
0answers
67 views
Variable scope in nested NMaximize, NMaxValue
I'm trying to use NMaxValue inside other statements (FindRoot and NMinimize). Those statements should bind variable names, but I'm getting weird warnings which seem to indicate that the variables ...
1
vote
3answers
203 views
Adding subscripts to variables
I know I can define
vars = Map[Subscript[x, #1] &, {"tem", "pressure", "hum", "lat", "alt", "space", "corner"}]
and
...
0
votes
0answers
53 views
Generalising propagation of covariance for sums of indexed variables
this is my first post in mathematicaSE. I have a question relating an answer given in an earlier <post>. Oleksandr uses as an example the expression
...
8
votes
1answer
103 views
Is it possible to use the global definition of a symbol as part of its new local definition set in a Block?
Consider the following expression:
Block[{Print = CopyToClipboard}, doSomething[]]
Now all calls to Print from ...
7
votes
3answers
196 views
Is it possible to define custom compound assignment operators like ⊕= similar to built-ins +=, *= etc?
I would like to do something like this:
...
1
vote
1answer
240 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 ...
1
vote
2answers
119 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 ...
8
votes
2answers
167 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 ...
8
votes
1answer
131 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]
...
10
votes
1answer
299 views
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
3
votes
2answers
229 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 ...
4
votes
4answers
130 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
...
0
votes
4answers
172 views
Specify a variable as an integer
I have a formula that always evaluates to a certain number for any variable X under one condition that X is an integer and ...
1
vote
1answer
103 views
Generating a list of symbolic coefficients [duplicate]
I am trying to do something which I assume should be very simple: I want to generate a list with symbolic coefficients that looks like this:
...
5
votes
2answers
139 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 ...
3
votes
1answer
131 views
How to replace variables in an expression?
I have generated a matrix using Mathematica,
$\left(
\begin{array}{ccc}
\text{cos$\theta $} & -\text{sin$\theta $} & \text{cos$\theta $}\, \text{dx}+\text{dx}-\text{dy}\, \text{sin$\theta $} ...
4
votes
2answers
81 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
...
2
votes
3answers
157 views
How to make a defined symbol stay in symbol form?
How to make a defined symbol stay in symbol form?
w = 3; g = 4;
{w, g}[[2]]
3
I want the output to be ...
0
votes
1answer
90 views
Riffle not acting as expected [closed]
I have defined two tables:
R = Table[Subscript[\[ScriptCapitalR], -i], {i, -12, -1}]
T = Table[Subscript[\[ScriptCapitalT], -i, -i - 1], {i, -12, -1}]
I want to ...
3
votes
2answers
202 views
Save variables values and definition
I used to do a lot of programming in R and recently switched to Mathematica. One thing that bothers me is that I haven't found a way to save variables, their values and definition!
Let's look at an ...
4
votes
1answer
333 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
0answers
28 views
How to define a vector of arbitary length [duplicate]
I need to use a vector of length which I can change, indexed symbolically
So for e.g. when N=3 I'd like to have
vec={c1,c2,c3}
when N=5
...
5
votes
1answer
180 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. ...
3
votes
1answer
95 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 ...
2
votes
1answer
78 views
Strange behaviour of variables in Table
I'm trying to work with some vectors and have run into a strange problem. An obvious way to define a difference of two vectors would be
dif[x_,y_] := x-y
I ...
5
votes
1answer
107 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....
2
votes
2answers
439 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 ?
1
vote
2answers
136 views
Why does Evaluate[a[[1]]]=0 assign a value to a variable while a[[1]]=0 doesn't?
I'm trying to do a small page counter with Mathematica, for leting me know about my reading progress on some books. I'm stuck on a problem:
...