# 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.

448 questions
Filter by
Sorted by
Tagged with
41 views

### Matching two lists and create variables

I have two lists of the same length. One of the lists has all the variable-names in it and the other one is a list of lists in which each list represents a value. I now want to automatically create as ...
93 views

47 views

### Define variables dynamically to compute a function

Let's say I have defined a function $W(p, q)$, where $p$ and $q$ are integers between (and including) $0$ and $2$ and the function takes me to a real number. Upon an input $n$, where $n$ is a positive ...
32 views

### Plot SinglePredictionBands associated with a FittedModel (e.g. LinearModelFit) that is supplied as a variable

I am puzzled about how to plot the SinglePredictionBands associated with a FittedModel (e.g. ...
48 views

### Overwrite a tensor product notation a_\[TensorProduct]b_ := KroneckerProduct[a, b]

I noticed that the definition of KroneckerProduct and For example TensorProduct[({ {0, 1}, {1, 0} }), ({ {0, 1}, {1, 0} })] Output: {{{{0,0},{0,0}}...
37 views

### user-defined functions and "pattern" being returned [closed]

I define a function as f[J_] := Exp[J^2/2\[Mu]] but when I try to taylor expand as k[J_] = Series[f[J] ,{J,0,2}] I'm getting ...
70 views

### Creating new variable names, Symbol or ToExpression

One can create new variable names by Symbol : In Table[Symbol["x"<>ToString[i]], {i,1,5}] Out {x1,x2,x3,x4,x5} But it is also possible to ...
49 views

### a variable as all values from a list

I have a small Problem with lists and variables. I want mathematica to calculate a formula I derived for 200 values of w between 0 and 5 in ascending order. (maybe I can define w along the lines of) <...
62 views

### Dynamic updating problem

Consider the code ...
92 views

Suppose you want to access a variable defined in a "surrounding" context (scoped via Begin and End) from within ...
36 views

129 views

### Why does f[set_]:=AppendTo[set,5] not work when applying f to a set?

The following code works ccc = {}; AppendTo[ccc, 5]; ccc and gives the output {5} However, the following code does not work: <...
135 views

### Construct 1 variable function from given 2 variable function

Given a function f[x , y]. The definition of f is not self-describing. (f was defined with objects other than f.) Then I want to construct a function g[x] such that f[x,y] and g[x][y] are the same, ...
56 views

### Certain plotting functions are setting variables unwantedly

I came across the following problem. Certain plotting functions set variables to values, which I do not want. For example, if I run SliceVectorPlot3D with an ...
31 views

### Redefining the output of a function

ftn1 = Sin[s]^2 + 3 t^2 + u^5 3 t^2 + u^5 + sin[s]^2 ftn2[s_, t_, u_] := ftn1 ftn2[2, 1, 2] 3 t^2 + u^5 + Sin[s]^2 Hi ...
68 views

### Display assumptions of a variable

If I restrict a variable x to x>0 via \$Assumptions=x>0, is there a way I can get ...
68 views

### Passing symbols, variables and defining functions within functions

Moderators state: “You will be brief and straight to the point”, and so do I. All codes test whether a polynomial is even or odd, using different approaches. This works: ...
127 views

### Function incorrectly renaming variables in Rule Pattern

Consider the simple pure Function containing a Rule with the named pattern q. ...
34 views

### evaluating some of the same variables inside a function while some of them are declared beforehand

This is a style question I suppose, not sure. Ok so I have this: a := RandomInteger[{1, 10}]; f[a_] := a - a f[a] ...
51 views

### Proper way to construct a function that takes too long to plot and integrate

Consider the functions phi[t_] and psi[t_] defined in the code below. These are used as basis functions for interpolation ...
108 views

### 'Do' loop acting on a global variable

I need a code that will allow me to alter a matrix (a global variable) iteratively using a function update (which depends on ...
33 views

### Variables with super/sub scripts

So I know how to create variable names with subscripts/superscripts at the end (using ctrl+_ etc), however, how would I use them in the middle of a variable name?
79 views

### Issue with several replacements in a function under certain conditions

I am trying to define a function (reduce[x]) which does several substitutions, depending on the values of certain parameters. Concretely, consider an expression x, which contains an arbitrary number ...
63 views

### Define/store individual elements of Table output for back-substitution

At its core, mine is a very simple communication error between me and Mathematica that I haven't been able to crack, so I do apologise if it seems embarassingly inane. Please consider the following ...
50 views

### Getting error messages form Set while trying to implement the bisection method with a For-loop [duplicate]

My objective is to build a function using modules that runs the bisection method. I have a working bisection method but when I try to implement it as a module I keep getting this error and I can't ...
39 views

### Multiple functions compact form

I have a sort of silly question... I need to define two functions in the following way ...
82 views

### Save a Derivative

I have defined the derivative of a function Derivative[f][x_] := Sin[x] How can I save this definition in a file? Derivatives are not included in ...
242 views

### How can we make the input of a function multiple lists?

I want to create a function that takes inputs that are multiple lists of ordered quadruples. For example, when we run the code our input line should read something like inputs[{2,3,4,5},{6,7,8,9},...} ...
48 views

### Compact notations for multiple variables

Why does this work Manipulate[ListPlot[{a,a,a}], {a, 0, 1}, {a, 0, 1}, {a, 0, 1}] But this doesn't? ...
51 views

### Defined function keeps the variable

I'm a beginner at Mathematica, and I have a problem finding the roots of a function for a specific variable (using Jens' findAllRoots function). Due to the nature of my problem, I need to compute ...
184 views

### KeyExistsQ[] but for functions?

Is there a good way to check if, say, f has been defined if f is a function, similar to ...
444 views

### Create variables in a for loop

I am very new to mathematica, but it would be much easier for me to use For loops in order to create variables. My train of thought was simple, but apparantly does not work. Let's say I defined these ...
55 views

### Number of values stored in a function

Suppose I run this: f = 1; f[n_] := f[n] = 2 f[n - 1]; f Now there will be 1001 values stored in f, and ...
47 views

### How to Append the value of a variable and not the variable itself

So lets say I have a = Some complicated code that changes list = {} AppendTo[list, a] Obviously it would give me ...
28 views

### Referencing data in sets of sets

Given a data set how to assign definitions to the subsets. For instance given the data data = {{0, 1, 1}, {0, 1, 1}, {1, 1, 0}, {0, 1, 1}, {1, 1, 0}} if {0, 1, 1} ...
833 views

### When is a symbol a Symbol? Is there an easy Mathematica way to test if an object is a symbol sort of like a SymbolQ?

Yes I know there is no built-in native function called SymbolQ (but JavaScript does). However, could one be simulated to work for most cases? I often rely on ...
I am trying to write a function in mathematica which depends on different parameters. For example $$f(x_1, x_2, x_3, x_4, x_5)= 2x_1+\sin(x_2)+x_3*x_4-x_5^{-1}$$ (My actual function has 12 such ...