Questions tagged [variable]

Questions on the use or manipulation of Mathematica variables (i.e. names associated with a changeable value). Use [variable-definitions] or [assignment] for questions on variable context localization, or assignment.

Filter by
Sorted by
Tagged with
25
votes
5answers
5k views

Extracting variables from an expression

I'm looking for a way to extract a list of variables from an expression, for example with an input like: ...
17
votes
2answers
415 views

When to name a variable with $

There are some symbols in the Wolfram Language that start with $, including $Abort, ...
16
votes
3answers
441 views

For any symbol, how can I get the full context-qualified name of the symbol as a string?

I'd like to have a function, whether built-in or not, that when given a symbol, whether bound to a value or not, returns a string giving the context and name of the symbol. Example: ...
13
votes
1answer
12k views

Get expression type?

Is there a built in function that distinguishes between different kinds of variables? I mean something like: VariableType[ 123 ] Number ...
11
votes
2answers
537 views

Is there a convention on which name to use for a throwaway variable? (Like underscore in Python) [duplicate]

I would prefer to write {_, foo} = LongFunctionName[arg1, arg2] instead of foo = LongFunctionName[arg1, arg2][[2]] or ...
10
votes
6answers
1k views

Generate list of strings from a list of assigned variables

How do I generate a list of strings from a list of assigned variables? E.g. convert ...
9
votes
1answer
2k views

What is and isn't a valid variable specification for Manipulate?

I have an expression whose terms have arguments (representing subscripts), like this: myExpr = A[0] + V[1,T] I would like to put it inside a ...
9
votes
1answer
734 views

Why does one of my Manipulate integer variables get turned into a real?

Bug introduced in 9.0 or earlier and persisting through 11.0.1 or later I'm developing code for manipulating graphs. Spot the difference in the 2 Manipulates below: ...
8
votes
4answers
1k views

Assign values to variable names in lists [duplicate]

I hope somebody can help me in this (I guess) simple question: I have a list of variable names ls={w0,w1,w2} and another list of values ...
7
votes
5answers
1k views

Checking if all the variables are present in the defined function

I want to check if a user input the function with all the specified variables or not. For that I choose the replace variables with some values and check for if the result is a number or not via a ...
7
votes
2answers
317 views

Apply ToString to a list of variables [duplicate]

I have data1 = {1, 1}; data2 = {2, 2}; datalist = {data1, data2}; I want to create a string list based on the variable names inside ...
7
votes
2answers
2k views

Display variable name instead of value

Is there a way to display the variable name instead of its value? for example, I need something likevarname = 1; function[varname]; and the output is ...
7
votes
2answers
519 views

Ignore some values at return

Is there Mathematica analogue of Python _ (underscore) or Matlab ~, a special variable, that can be used when a function returns ...
7
votes
1answer
220 views

Tremendous bug using EstimatedDistribution (using NMinimize) in v8.0 and v10.2

Let's define F4 and estimate the distribution of the data: ...
6
votes
3answers
469 views

How to transform a function from f[#1] to f[x]

So I have this function : Sqrt[-1 + Tanh[#1 - #2]^2] & How can I transform it into f[x_,y_]=Sqrt[-1 + Tanh[x - y]^2] ...
6
votes
2answers
269 views

Want to return name of last defined variable without explicitly naming it

Suppose I have this code: dec = 7.1 + 6.6 + 27.2 + 66.5 jan = 7.1 + 6.6 + 27.2 + 66.5 + 65.7 feb = 7.1 + 6.6 + 27.2 + 66.5 + 65.7 + 69.7 And I want MMA to return:...
6
votes
4answers
202 views

Assigning a string to variables names

I have the list n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv\"}}. That is {{variable name, string}, {name, string}}. I want ...
6
votes
1answer
271 views

An alternative to subscripts?

Are there any good alternatives to using subscripts to keep track of and uniquely identify many variables? I know that subscripted variables behave badly. Thanks!
6
votes
1answer
905 views

Variable number of nested variable-range sums

I would like to express the following nested sum in Mathematica: $$ S(m,j,N) = \sum_{k_1=m+j-1}^{N-1} f(N,k_1) \sum_{k_2=m+j-2}^{k_1-1} f(k_1,k_2) \cdots \sum_{k_m=j}^{k_{m-1}-1} f(k_{m-1},k_m) $$ ...
6
votes
0answers
64 views

Nested rules and automatic renaming of variables [duplicate]

I understand why $ happens here: ClearAll[foo] foo[a_] := (x_ :> a x) foo[1] ...
5
votes
4answers
285 views

Name a list with Table

I am struggling to find a way to assign a value from a list to names from another pre-defined list with Table[]. names = {first, second, third} ...
5
votes
1answer
99 views

Make assumption for function with variable argument

I would like to assume that a>t[b_] for any b, such that e.g. Simplify[a>t[c]]==True. ...
5
votes
2answers
637 views

Series expansion of a multivariable function to an order n for any number of variables [duplicate]

Suppose I want to expand a multivariable function to an order n. ...
5
votes
3answers
376 views

One inequality with two variables

I would just like to know if this: ((a - b)/(b*Log[b])) - Log[Log[a]] + Log[Log[b]] exceeds 0 for any combination of a and <...
5
votes
1answer
409 views

How to make Mathematica express an equation in terms of previously defined functions

I was given a problem for my physics class, and perhaps I have taken it too far, but I wish to finish what I started. I have a function (i warn you that this does not look pretty) ...
5
votes
1answer
78 views

Computing Higher Order Tensor of Variable Rank

The following code takes a vector x of variable length, computes the outer product of the vector with itself to form the matrix $\rho$ of dimension $2^n \times 2^n$....
5
votes
1answer
716 views

How to re-assign values to a List of variables?

The accepted Answer to this similar Question can only be used one time, so it's not suitable for my problem. I do high-dimensional calculations for which I need to make lists of variables, like so: <...
4
votes
1answer
253 views

Why is DSolve different when the equation is built programmatically?

Here is a simple differential equation. mwe=y[x]/.First@DSolve [{y'[x]==x-2*x*y[x],y[0]==0},y[x],x] I get the answer $\frac{1}{2}-\frac{e^{-x^2}}{2}$ If I build ...
4
votes
1answer
134 views

Map[Remove[#]] doesn't seem to do anything

If you have a symbol with a value, you can clear it with Remove[]. Thus ...
4
votes
1answer
189 views

Context inside Do[…]-loop

Consider the following code: Begin["mycontext`"]; myvar = 7; Print[Context[]]; Print[Context[myvar]]; End[]; with the output mycontext` mycontext` Now ...
4
votes
2answers
6k views

Using Array Elements as Function Arguments

Suppose I have an array p = {a,b,c,d} and a function f that takes a variable number of arguments. I want to evaluate ...
4
votes
1answer
50 views

Name of patterns cast as expressions from strings

I'm trying to match a part of a string while imposing conditions on the patterns, e.g.: StringCases["223", a: DigitCharacter ~~ b: DigitCharacter /; Unequal[a, b]] ...
4
votes
2answers
191 views

How to find variables set through Get[“/some/path/dump.mx”]? [duplicate]

(NB: I could not find any good tags for this post. Please feel free to add better ones.) Suppose that the file /some/path/dump.mx was generated during an earlier ...
4
votes
2answers
621 views

Combining Multiple Lists

Let's say I have 4 lists: list1 = {a,b,c,d}; list2 = {e,f,g,h}; list3 = {i,j,k,l}; list4 = {m,n,o,p}; I can combine them using Join ...
4
votes
1answer
480 views

Is it possible to find the size of a variable in a notebook?

I have a fairly large a list of matrices matsLst, which takes about 15 minutes to compute (but computes successfully each time). I can test in the notebook that ...
4
votes
2answers
241 views

Button with loop that iteratively updates slider in Manipulate

I have the toy Manipulate. ...
4
votes
1answer
147 views

Checking if input is a function

I would like to write a program to find the leading coefficient of a given polynomial. (Sounds easy, right?) I'd like to be able to handle the format x^2-x+7 (with ...
4
votes
1answer
82 views

Use a variable to represent another variable?

I'm trying to create a list of functions by replacing variables in a template. I tried this: ...
4
votes
0answers
635 views

Multiple variable assignment from a list [closed]

For example in Python, if we have a list of 3 elements, say ls = [1,2,3] and we want to assign a variable to each value (from left to right), one can do as follows: ...
3
votes
1answer
728 views

General::ivar 0 is not a valid variable when using Series in Plot

I have been having some trouble graphing a Taylor series approximation (Series). ...
3
votes
3answers
813 views

Getting a list of variable names as strings via a function

This is a new twist of an earlier question about how to get variable names as strings from a function. I would like to have a function that returns a list of variable names, each being a string, from ...
3
votes
2answers
90 views

From f[g[x,t]] to f[g]

How can you change f[g[x,t],t] to f[g,t] ? I have differential equations ...
3
votes
2answers
65 views

Better way for constant expressions in functions than storing as global variables?

For example, I wrote a function like this: inversions[list_] := Complement[ Subsets[{1, 2, 3, 8, 4, 7, 6, 5}, {2}], Subsets[list, {2}] ] But as you see, ...
3
votes
2answers
218 views

Define a function of a function of an arbitrary variable

I want to define a function called int that takes another function as an argument and yields an integral of that function from 0 to 1 (just for example). So I ...
3
votes
2answers
118 views

Solve and naming variables

Let's say, I do this: ...
3
votes
1answer
88 views

Again about Module inside other Module

Let me start with a short preamble. I have a large function (defined through other functions) which I need to integrate numerically. This works. Trying to speed up the process, I played with ...
3
votes
2answers
173 views

Using Symbolize to Convert Multiple Variables at Once

So, I have created a list of subscripted and overdotted variables that I would like to symbolize, so I run them through a for loop. Seems to me that this would work? Any help is appreciated. ...
3
votes
3answers
438 views

Creating a List of Symbolized Indexed Variables

I am trying to creat a list of indexed variables (symbols) using the Notation package and Symbolize command. As an example, ...
3
votes
1answer
163 views

How can we define lots of variables

I am new to Mathematica and some things I do not understand. Right now I need to write an algorithm which takes a polynomial in many variables, I denote it by $p_{i,j}$, and then I want to apply a ...
3
votes
1answer
187 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) ?

1
2 3 4 5 6