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.

Filter by
Sorted by
Tagged with
8 votes
1 answer
100 views

Very simple, unexpected Low Performance of set(=)

...
user avatar
  • 2,825
0 votes
0 answers
37 views

How can I "map thread" similar notation definitions in one line?

In the past few days I have been dealing with different integral notation definitions made by myself. I have noticed several similar notation definitions with a common pattern, but currently I am only ...
user avatar
  • 383
5 votes
1 answer
190 views

Is K is a function? [duplicate]

Some of the capitalized single letters are functions. Starting a fresh kernel and typing in the 24 capital letters, the following letters turn black since they are special functions, ...
user avatar
  • 1,947
0 votes
1 answer
62 views

How to define prefix that can turn numeric?

I put these prefix in my init.m file. First I Unprotect all these symbols, set values and then ...
user avatar
  • 1,862
0 votes
0 answers
29 views

Global assumption non zero

I would like to define globally an assumption stating that I have a nonzero real vector $v$. For now, I put : $Assumptions = Element[v,Vectors[{100},Reals]] but $v$ ...
user avatar
  • 442
0 votes
0 answers
95 views

See variable as byte

I see variable v is occupying 112 bytes of my RAM. v = {3, 5, 7}; ByteCount[v] 112 Then how to see the content of the 112 bytes?...
user avatar
  • 2,825
0 votes
1 answer
77 views

How to convert mathematica root expression to readable one? [duplicate]

I am trying to find out at what regions a function is monotonically decreasing. The function is a function of X and has two more variables epsilon and B with the constrains 0 < B, 0 <epsilon< ...
user avatar
  • 5
0 votes
0 answers
36 views

How can I prevent functions and variables from being automatically cleared when I close Mathematica? [duplicate]

The following happens with every notebook I make: I define functions and variables. When I quit Mathematica and reopen the notebook, all of those definitions have been cleared. The functions and ...
user avatar
2 votes
2 answers
152 views

Why is the parametric plot failing?

I tried running the following code but it doesnt seem to be working, it seems to be stuck on running. I think it's got something to do with the way I am defining functions with a variable integration ...
user avatar
7 votes
0 answers
102 views

Defining a SparseArray functions in Mathematica 13

I am defining a sparse array as a function of argument x, i.e. f[x_] = SparseArray[{1->x}, {3}] In Mathematica 12 this works perfectly, I can pass arguments and ...
user avatar
  • 71
0 votes
1 answer
58 views

Part of array as a blank variable [duplicate]

I have a little question. Let me define the function: f[k_]:=k So 'k' in the argument of 'f' is a blank variable. Is there a way to define a part of array as a ...
user avatar
0 votes
1 answer
76 views

Errors appear after integration of an interpolating function

I have a little question about integration of an interpolating function. There is an error in assumptions of the integral. I have a function that was obtained with an interpolation method: ...
user avatar
0 votes
0 answers
84 views

Plot implicit function with intermediate variable

Cross-posted in Wolfram Community. Here, I intend to plot a 3D picture of with two implicit functions where $x, y, t, \xi, \eta$, are variables. Of course, these variables can be constrained to ...
user avatar
  • 93
1 vote
1 answer
69 views

Numerical integration in one variable, of a multivariable interpolation function

I create the following set of data: newmatrix = Flatten[Table[{t, v, new[t, v]}, {t, 0, 2 Pi, Pi/4}, {v, 0, 1, 0.01}], 1] where ...
user avatar
1 vote
1 answer
74 views

expression evaluation for Compile[] too time consuming

I need to use Compile[] for a very large expression to be integrated. But for Compile[] the expression has to be evaluated, and this takes endless time. The expression is composed of several functions ...
user avatar
  • 135
2 votes
2 answers
85 views

Problems with TagSet

I am new with TagSet and TagSetDelayed and I'm not understanding properly how they works. I introduced the following definition: ...
user avatar
  • 119
0 votes
1 answer
46 views

Is always possible to define a numerical value using subscript?

In this code I defined some values using subscripts and it is not the first time I did this but strangely the code execution crashes. To follow the code. ...
user avatar
3 votes
2 answers
142 views

Making a list of variables

Consider the following code, which give a Manipulate object that returns the "total" of a certain variable var 1 ...
user avatar
  • 4,228
1 vote
2 answers
68 views

Remembering function definitions across sessions to avoid recalculation [duplicate]

I'm working with some large expressions and fourier transforms, which usually take a long time to compute. When I save my notebook with outputs to all my inputs, I'd like it to remember those ...
user avatar
1 vote
0 answers
46 views

Defining a function expression [duplicate]

I'm sure this has been answered before, but imagine I have the following function ...
user avatar
  • 4,228
0 votes
0 answers
46 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 ...
user avatar
2 votes
2 answers
97 views

Unexpected Behavior in `Sum[a + Subscript[a, 1], {a, 1, 2}]`

The simple command Sum[a + Subscript[a, 1], {a, 1, 2}] gives the unexpected result 4 + Subscript[2, 1] while what I want is $3+...
user avatar
7 votes
2 answers
252 views

Copy a function instead of referencing [duplicate]

Is there an option to let me assign the old function of f to g, without changing g when reassigning f? This piece of code describes my problem: ...
user avatar
  • 563
3 votes
1 answer
75 views

Performing matrix tensor product and getting a sum of its negative entries

I am given a $3 \times 3$ matrix $M$, which only has real entries. Is there an efficient way to do the following two operations with $M$? For a given input $n$, compute the $n$-fold tensor product $M^...
user avatar
2 votes
1 answer
82 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 ...
user avatar
0 votes
1 answer
60 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. ...
user avatar
  • 3
3 votes
0 answers
56 views

Definition of large expression - makes PC freezed

In[1] A=Range[10^4];?A Out[1] (* definition of A*) It works for 10^4. But if I increase the number to 10^6 ...
user avatar
  • 2,825
2 votes
2 answers
87 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}}...
user avatar
  • 823
1 vote
1 answer
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 ...
user avatar
0 votes
0 answers
100 views

Creating new variable names, Symbol or ToExpression

One can create new variable names by Symbol : In[1] Table[Symbol["x"<>ToString[i]], {i,1,5}] Out[1] {x1,x2,x3,x4,x5} But it is also possible to ...
user avatar
  • 2,825
0 votes
0 answers
53 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) <...
user avatar
1 vote
1 answer
68 views

Dynamic updating problem

Consider the code ...
user avatar
  • 4,228
1 vote
3 answers
102 views

Access to variables in surrounding context from within Manipulate

Suppose you want to access a variable defined in a "surrounding" context (scoped via Begin and End) from within ...
user avatar
1 vote
1 answer
55 views

Changing expression using a new variable definition

If I have an expression that looks like the following: $$ \frac{i \sqrt{\frac{\sigma _2}{\sigma _1}} \left(-\sigma _2 q_1(t){}^2+\sigma _1 q_2(t){}^2+\left(\omega _2-\omega _1\right) q_2(t) q_1(t)\...
user avatar
8 votes
1 answer
474 views

very simple but unexpected aspect of Function[ ]

I've always thought (2#+1)& and Function[x,2x+1] are interchangeable in common sense. But, ...
user avatar
  • 2,825
0 votes
0 answers
21 views

Partially activate a derivative

Is there a way to make an inactive derivative do some amount of simplification? For instance, say I have Inactive[D][{{f,g},{u,v}},x] I would like ...
user avatar
  • 1,478
0 votes
1 answer
55 views

Nested usage of NIntegrate

I'm trying to compute an integral of f(x,y) such that an integration over "y" is performed inside the integral over "x". My trial is below: <...
user avatar
  • 3
4 votes
1 answer
28 views

KroneckerProduct with arbitrary number of Pauli matrices

I want define a function of n variables as follows $$f(x_1, ..., x_n)= KroneckerProduct[\sigma^{x_1}, ..., \sigma^{x_n}]$$ where $\sigma^{x_i}=PauliMatrix[x_i]$. Given a number $n$, I can explicitly ...
user avatar
  • 251
3 votes
1 answer
65 views

Definition of multiple variables from a list

I have a list of the form {{0, 0, 0, 0, 0, 0, a, b, c, d, e, f}, {0, 0, 0, 0, 0, 1, a, c, b, d, f, e}, {2, 2, 2, 2, 1, 2, b, f, c, a, d, e}, ... } and I would ...
user avatar
  • 327
3 votes
0 answers
79 views

Module inside With, With inside Module, or Just Module?

In general, if one wants to define local variables and local constants, which of the following is the best programming practice in terms of performance and code "safety"? (Assume ...
user avatar
1 vote
1 answer
130 views

Solve using PolyGamma function

I am trying to solve for the value of y. My code is: x = 0.165; f = -Log[y] - PolyGamma[0.5 + 0.2*(x/y)] + PolyGamma[0.5]; Solve[f == 0, y] Running gave me ...
user avatar
  • 21
0 votes
0 answers
65 views

How to declare a list of symbols as Real numbers?

I have a list of symbols : gammaVecs =Table[Symbol[StringJoin["gamma", ToString@j, ToString@i]], {j,7}, {i, 40)}]; Which I want to use later in ...
user avatar
  • 912
7 votes
2 answers
352 views

Is it possible to define conjugate of a function?

Could you help me, please? I have two complex functions of real variable f[x] and fc[x] such that one is a conjugate of another one. I'd like to take a conjugate of an expression that includes both of ...
user avatar
  • 153
0 votes
1 answer
86 views

How to implement this recursion relation?

I am trying to implement the following relation in Mathematica for any $k$: $$\begin{align} t_{n,n_1, \ldots, n_k} &= \frac{1}{2} \sum_{m=0}^{n-2} \left( t_{m,n-m-2,n_1, \ldots, n_k} - \frac{1}{N} ...
user avatar
  • 641
3 votes
2 answers
133 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: <...
user avatar
4 votes
1 answer
155 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, ...
user avatar
  • 2,825
2 votes
0 answers
58 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 ...
user avatar
0 votes
2 answers
58 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 ...
user avatar
2 votes
1 answer
79 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 ...
user avatar
0 votes
1 answer
69 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: ...
user avatar

1
2 3 4 5
10