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
-1
votes
0answers
59 views

Numeric integration with symbolic boundaries

The following is a definition of a numeric integration: ...
0
votes
1answer
55 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 ...
0
votes
1answer
54 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: ...
0
votes
0answers
77 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 ...
1
vote
1answer
54 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 ...
1
vote
1answer
65 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 ...
2
votes
2answers
83 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: ...
0
votes
1answer
43 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. ...
3
votes
2answers
136 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 ...
1
vote
2answers
67 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 ...
1
vote
0answers
45 views

Defining a function expression [duplicate]

I'm sure this has been answered before, but imagine I have the following function ...
0
votes
0answers
45 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 ...
2
votes
2answers
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+...
7
votes
2answers
243 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: ...
3
votes
1answer
72 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^...
1
vote
1answer
62 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 ...
0
votes
1answer
46 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. ...
1
vote
2answers
59 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}}...
1
vote
1answer
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 ...
0
votes
0answers
74 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 ...
0
votes
0answers
51 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) <...
1
vote
1answer
67 views

Dynamic updating problem

Consider the code ...
1
vote
3answers
94 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 ...
1
vote
1answer
41 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)\...
8
votes
1answer
460 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, ...
0
votes
0answers
18 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 ...
0
votes
1answer
52 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: <...
4
votes
1answer
24 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 ...
3
votes
1answer
60 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 ...
3
votes
0answers
78 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 ...
1
vote
1answer
117 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 ...
0
votes
0answers
50 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 ...
7
votes
2answers
330 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 ...
0
votes
1answer
82 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} ...
3
votes
2answers
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: <...
4
votes
1answer
143 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, ...
2
votes
0answers
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 ...
0
votes
2answers
51 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 ...
2
votes
1answer
71 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 ...
0
votes
1answer
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: ...
3
votes
2answers
138 views

Function incorrectly renaming variables in Rule Pattern

Consider the simple pure Function containing a Rule with the named pattern q. ...
1
vote
0answers
35 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] ...
0
votes
0answers
55 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 ...
1
vote
2answers
119 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 ...
1
vote
0answers
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?
0
votes
0answers
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 ...
1
vote
1answer
68 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 ...
0
votes
1answer
54 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 ...
1
vote
1answer
39 views

Multiple functions compact form

I have a sort of silly question... I need to define two functions in the following way ...
0
votes
2answers
88 views

Save a Derivative

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

1
2 3 4 5
10