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

1
vote
1answer
131 views

Is linear interpolation applicable here

From my understanding about Linear Interpolation especially of that of Newton's Divided Difference Polynomial, we could get the value of F(x) from the given set of ...
6
votes
1answer
145 views

How can I define a ⊕ operator?

What is wrong with the following code? CirclePlus := SparseArray[Band[{1, 1}] -> {##}] & a_ ⊕ b_ := CirclePlus[a, b] SetDelayed::write: Tag Function in ...
19
votes
3answers
365 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: ...
4
votes
1answer
164 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 ...
3
votes
1answer
153 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
vote
1answer
123 views
1
vote
1answer
84 views

Plotting with multiple variables [closed]

What is the simplest way of plotting across multiple variables? eg: I would like to plot something like this: Plot[{x^0,x^1,x^2,x^3,x^4,x^5,x^6}, {x, 0, 10}] ...
10
votes
4answers
424 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 ...
0
votes
0answers
90 views

NIntegrate with an arbitrary number of variables [duplicate]

I need to evaluate NIntegrate with a variable number of variables. Here's a concrete example. I'll accept an answer that finds a way to make the example work. I ...
3
votes
2answers
120 views

Assigning an equation as a variable

I am compiling a calculator where many slider parameters are used to define a value, where the defined value may then be reused to define another value. I am unable able to, or at least been ...
3
votes
3answers
111 views

Using a variable to tell Mathematica which existing variable to manipulate

I have an estimation routine I have coded up, I want now to do some tests on it where I pick a particular parameter and run the estimation for differing values of that parameter. What I want is to be ...
0
votes
0answers
36 views

Subscripts to a variable; why a letter shoud come before a digit?

I noticed that I cannot create a variable $f_{2s}$ since Mathematica seems to leave a space between the subscripts 2 and s ...
1
vote
2answers
122 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
65 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
201 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
82 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
125 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
203 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
752 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
110 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 ...
4
votes
4answers
340 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
97 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
178 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 ...
6
votes
2answers
324 views

Obtaining the name of a variable as a string [duplicate]

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
154 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
317 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
157 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 ...
12
votes
3answers
294 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
101 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
93 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
111 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
182 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
167 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
146 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
114 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
330 views

Adding subscripts to variables

I know I can define vars = Map[Subscript[x, #1] &, {"tem", "pressure", "hum", "lat", "alt", "space", "corner"}] and ...
8
votes
1answer
120 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 ...
1
vote
1answer
554 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
192 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
217 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
151 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] ...
13
votes
1answer
615 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
243 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
147 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
556 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
207 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: ...
7
votes
2answers
190 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
155 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
87 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 ...