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.

Variable name basics:

  • Mathematica variables can have multiple letters and numbers in their names, but names are not allowed to begin with a number.

  • A generally accepted practice is to avoid starting variable names with capital letters, since Mathematica's own built-in commands and variables all begin with capital letters. Using lower-case when creating your own variables helps prevent possible conflicts with built-in commands.

Tips for creative naming (copied from a MathGroup post by David Park):

SpecialCharacters

NonPrintingCharacters

LetterSpace

TextualForms

UnderBracket

These are both Symbols and can be used as variables:

my\[LetterSpace]first\[LetterSpace]variable

my\[UnderBracket]first\[UnderBracket]variable

LetterSpace has the alias esc ls esc. UnderBracket has the alias esc u[ esc.

Another "special form" that can be used for primed and double primed symbols:

x:02b9 which gives x'

x:02ba which gives x"

These have the Head Symbol and can be used for variables. They are not confused with derivatives and the primes are at the proper level.

338 questions
7
votes
2 answers

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 varname instead of 1
Yituo
  • 1,389
  • 9
  • 15
7
votes
1 answer

How to Obtain Complete List of Properties

I am working with Matrix Market matrices in Mathematica (specifically GEMAT12), and I saw from other posts that you call properties of a variable exemplified below: A = Import["gemat12.mtx"]; A["Density"] A["Dimensions"] With the following…
Chloe
  • 165
  • 6
3
votes
1 answer

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 differential operator on it. Something like…
Badshah
  • 267
  • 1
  • 6
2
votes
0 answers

How to list all user-defined variables with current values?

How to get a list of all user-defined variables and those current values in the current .nb? Maybe it's a (too) simple question, sorry if so, but the answer would help me a lot in debugging some stubborn code...
Conrad
  • 723
  • 4
  • 10
2
votes
1 answer

Assiging random values to an array of variables

I want to create a number of variables and assign random values to them. This is possible in Python using a single line of command. To be more specific say I want to create 10 variables whose value will be $[0.1,1]$ randomly. Instead of declaring…
jhon_wick
  • 249
  • 1
  • 7
2
votes
1 answer

How to choose variables of specific form

I am trying to work on a problem with a probability distribution. I wanted to get the result in analytical form. Suppose I need to keep p1, p2, p3, p4 variables such that p1+p2+p3+p4=1; How to use this information (p1+p2+p3+p4=1) in mathematica so…
kphy
  • 35
  • 5
2
votes
0 answers

a basic question about variable in Mathematica

I can't describe exactly the problem I'm experiencing, but this kind of problem has a remarkable feature, that is, commands which couldn't work in the before can be executed correctly when i turn off the Mathematica and reopen it. Later, I know…
Aerterliusi
  • 353
  • 1
  • 5
2
votes
3 answers

Assign an array of numbers to an array of variables

I have a huge array of variables like this. variables=Flatten[Join[ Flatten[Table[ alpha[i, j, k, l, m, n], {i, 0, 2}, {j, 0, 2}, {k, 0, 2}, {l, 0, 2}, {m, 0, 2}, {n, 0, 2}]], Flatten[Table[ beta[i, j, k, l, m, n], {i, 0, 1}, {j,…
StarBucK
  • 2,164
  • 1
  • 10
  • 33
1
vote
2 answers

Pass the list of variables into function to change their values

I'm new to Mathematica, so I don't really know, how do what I want, and I don't even know how to google it. Doing one Mathematica task for my supervisor, I faced the following problem. I need to write a function with such a syntax: f[{{var1, val1},…
kmingulov
  • 539
  • 2
  • 9
1
vote
1 answer

Why do For[] loop variables in different functions interfere?

I had something along the lines of: Func1[x_]:=(For[i=1,i
YungHummmma
  • 3,042
  • 15
  • 30
1
vote
1 answer

Equation with 3 variables running forever

I am new to this and was trying to solve an equation. Yet, it is taking more than 6 hours, and I am unsure if I typed something wrong or if my laptop settings are incompatible with the software. Any help would be appreciated! So, firstly, I found…
C. K
  • 25
  • 6
1
vote
0 answers

How to change expression of variable in output

I run the example: c = a - b; e^(a - b) This gives me e^(a-b). How can I do to let it output e^c
林怡君
  • 39
  • 4
1
vote
2 answers

Getting the name of a variable instead of its value

I want to get the name of a variable instead of its value in output. Say I have a function in which I have vectors e={1,0,0,1} and f={1,1,0,1}, and the input for the function is a symbol (e or f). Now, in output, I want to make a grid which shows…
Drobdien
  • 77
  • 4
1
vote
0 answers

Defining a variable to be greater than zero

I am trying to do some integrals over a region , however this region is going to depend on parameters $ \alpha , \beta $ and when calculating these integrals they give multiple values depending if $\alpha , \beta$ are greater or not than $0$. Is …
Someone
  • 175
  • 8
1
vote
1 answer

Unexpected behavior of Variables

I apologize in advance if this is a duplicate. Variables has a strange behavior when it encounters powers: w = s1^(n + 2) s2; Variables[w] (*{s1, s1^n, s2}*) I'd have expected {s1, s2, n}, On the other hand w = s1^2 s2; Variables[w] (*{s1,…
user46676
1
2