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.

43 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
0answers
104 views

Using an external Pattern breaks Format

I noted while writing this answer that using an external Pattern on Format doesn't work: ...
3
votes
0answers
74 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 ...
3
votes
0answers
61 views

Circumvent DistributeDefinitions

I have a code in which I create a few very large matrices with which I need to do long calculations. I have parallelised my code and, in the end, the thing that slows me the most is the time it takes ...
3
votes
0answers
60 views

Variable assignment/replacement issues

I have three questions about variable assignment. Module[{z}, z = y; p'[y] /. p -> Function[y, Evaluate[z]]] When I run the above code, it outputs 0. 1) If I ...
2
votes
0answers
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 ...
2
votes
0answers
544 views

How to declare variables with plus/minus sign as subscript/superscript?

I am pretty new to mathematica, so please forgive me if I ask any stupid questions. I want to create a vector $a^{+}=[a^+_{k-2},a^+_{k-1},a^+_{k},a^+_{k+1},a^+_{k+2}]$ and then do some symbolic ...
2
votes
0answers
192 views

Share variables among notebooks with different Kernels

So I have a server running in another notebook with a secondary kernel. I run my main notebook and launch the server notebook, but I have configured the variables in my main one, and can't find a way ...
2
votes
0answers
203 views

Changing variables in a series expansion

I want to compute the Taylor expansion of some pure function f[x_], but then perform a change of variables in the resulting expression. So, for example, the output ...
2
votes
0answers
80 views

Follow-up to “How to differentiate formally?”: Efficiency concern

In link to "how to differentiate formally?" and particularly to the answer by @Jens, I want to do something like this: ...
2
votes
0answers
139 views

How to create a complex variable from dated list values

Can anyone help me to construct a variable "PI" from values of variable x. Variable x represents a group of two time series rj and ri on equal dates(joined two dated lists with states).Variable x have ...
2
votes
0answers
1k views

specifying a list (vector) of arbitrary length

When trying to do symbolic calculations in mathematica involving a space of dimension n, which is arbitrary but fixed, I'd often like to work with vectors that have ...
1
vote
0answers
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] ...
1
vote
0answers
31 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?
1
vote
1answer
58 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 ...
1
vote
0answers
80 views

Issue with Solve, NSolve, FindRoot

I have this code that I've been trying to get working for some time. I asked some questions before which helped but still struggling! ...
1
vote
0answers
43 views

How to define a variable $x$ such that $Abs[x]<1$ and use this globally without having to re-write it again and again?

I am writing a code or a calculation of a very complicated function and my main variable is $x$ such that $-1<x<1$. This assumption has to simplify my final answer a lot, but since the final ...
1
vote
0answers
56 views

Tell Mathematica to use symbolic expression

I would like to achieve a function sin as in: T=Sin[t]; sin[x_]:=T/.t->x; But without this replacement rule. How can I ...
1
vote
0answers
144 views

Subscripts in variable names: Bug?

In the following plot, one of the two functions {-par, par} defined by ...
1
vote
0answers
309 views

Variable scope in nested NMaximize, NMaxValue

I'm trying to use NMaxValue inside other statements (FindRoot and NMinimize). Those statements should bind variable names, but I'm getting weird warnings which seem to indicate that the variables ...
0
votes
0answers
9 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
0answers
42 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 ...
0
votes
2answers
22 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 ...
0
votes
0answers
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 ...
0
votes
0answers
77 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 ...
0
votes
0answers
44 views

Definition of a real variable

I would like to calculate a definite integral with a real parameter "a". I tried Refine[Element[a, Reals]] and Simbols [Element] Reals but the yield was a ConditionalExpression dealing Im[a] and Re[a]...
0
votes
0answers
30 views

Evaluating global variable within a module

I'm trying to work with something like the following: a = b; f[x_, b_] := Module[{N}, N = Abs[a]; 10 N ] f[1, 1] The output of running this is: ...
0
votes
0answers
44 views

Set of multivarible expressions to be re-expressed a single variable

I have a set of expression such as $\frac{3x+y-z}{6x}$ and $\frac{3 x-y+z}{12 x}$, which can easily get re-expressed as $p$ and $(1-p)/2$, where $p=\frac{3x+y-z}{6x}$, but is there a way to find this $...
0
votes
0answers
40 views

Problema simulating FindRoot

I am writing a procedure that simulates the findRoot built-in function using the same code that appears at chapter 6 of $\textit{Programming in mathematica}$ by Paul Wellin. The code is the following....
0
votes
0answers
51 views

Variables for multiple data files plotting using same Mathematica notebook

I am not an expert in mathematica, I have this following code. As you see I import a text file under the name "MyPoint1", plot with "pAll" then I do some more calculation with more variables and ...
0
votes
0answers
38 views

Series expansion of explicit functions

For the following input, zv[u_, v_] := v + zv1[ u, v]/u; mvu[u, v] := D[zv[u, v], u]; Series[mvu[u, v], {u, 0, 1}] the output is ...
0
votes
0answers
108 views

Define the partial derivatives of a multivariable function

I have some vector $K = [K_1, K_2,...K_n]$ which is a function of variables $(x,y)$ i.e. $K = K(x,y)$ I want to symbolically calculate the partial derivatives e.g. $\partial_x K$, $\partial_x \...
0
votes
0answers
37 views

Defining a function through an ODE containing unspecified operators

I want to do some algebra using a function only defined through a DE containing unspecified operators. The DE is $$ \partial_zu(z) = \left[\hat{D}+\hat{N}(z,u)\right] u(z). $$ Here $u$ lives in ...
0
votes
0answers
60 views

List of all items stored in kernel

In Matlab, there is a window on the side that contains all of the variables stored in the workspace. Is there something equivalent in Mathematica? I am imagining a command kind of like DownValues or ...
0
votes
0answers
61 views

Assign a variable to an expression in Mathematica

I have the following matrix {{a^2 + b + \[Sqrt](m + n) + 5, 23 x + 7 a}, {14 b, a^2 + b + \[Sqrt](m - n) + 5}} I want to replace the expressions ...
0
votes
0answers
1k views

Using loop index for variable names?

I am trying to generate different variables in function of a loop index. In example: generating a list with var1 = 1, var2 = 2, ... ...
0
votes
0answers
66 views

Why 3 Different results for same Integral of a series?

I have the integral of a Series. According to some details, I get different outputs and I don't know which to rely on. Can anyone explain me the differences and if I am doing some mistakes? ...
0
votes
0answers
84 views

Why do I get Imaginary unit after Abs and Complex expand?

I am getting an imaginary unit in the output after Abs and saying Complex Expand, why? Then, when I integrate in x and z, I miss beta. I don't get why beta vanishes in the definite integral. ...
0
votes
0answers
372 views

Colors of variable mathematica

Suppose that I have an equation which goes like this: x = 2; yp = 2; y_p= 2; a = x + yp + y_p; Usually, once the variable is defined it will be of blue color and ...
0
votes
0answers
71 views

Using sub-scripted variables in functions

Is it possible to use subscripts in Mathematica functions, for example f[Subscript[x, a] _] := x^2 However this doesn't seem to work, is there a way to allow ...
0
votes
0answers
185 views

How can I cleanly distribute definitions of system functions?

I have a package that redefines a system symbol, and I am struggling to find a clean solution that will ensure that those redefinitions will still work inside a parallelized environment. The core ...
0
votes
0answers
53 views

Naming variables from other variables

I'm inside a Do loop and I'm constructing a Dataset. I have consumers that come each period and I need a unique identifier for each of the consumer. To uniquely identify a consumer I need 3 variables:...
-1
votes
0answers
47 views

Problem with KarhunenLoeveExpansion's output

I have a matrix called realizationMat, it contains 101 measurements of 90 realizations of a stochastic process. I will post instead an abridged 11*5 smaller example ...
-1
votes
1answer
122 views

Symbolic representation of Class Conditional Probablity as a variable

What is the best way to a create a symbolic variable to represent Class Conditional Probability in Mathematica e.g. $p(A|B)$