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
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 ...
2
votes
1answer
49 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
72 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
100 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
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 ...
7
votes
2answers
307 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 ...
1
vote
1answer
70 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
127 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
129 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
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 ...
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 ...
2
votes
1answer
61 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
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: ...
2
votes
2answers
123 views

Function incorrectly renaming variables in Rule Pattern

Consider the simple pure Function containing a Rule with the named pattern q. ...
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] ...
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 ...
1
vote
2answers
106 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
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?
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 ...
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 ...
0
votes
1answer
48 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
77 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 ...
2
votes
4answers
191 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},...} ...
0
votes
1answer
47 views

Compact notations for multiple variables

Why does this work Manipulate[ListPlot[{a[1],a[2],a[3]}], {a[1], 0, 1}, {a[2], 0, 1}, {a[3], 0, 1}] But this doesn't? ...
0
votes
1answer
48 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 ...
6
votes
3answers
182 views

KeyExistsQ[] but for functions?

Is there a good way to check if, say, f[5] has been defined if f is a function, similar to ...
6
votes
3answers
432 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 ...
1
vote
1answer
39 views

Number of values stored in a function

Suppose I run this: f[0] = 1; f[n_] := f[n] = 2 f[n - 1]; f[1000] Now there will be 1001 values stored in f, and ...
2
votes
1answer
39 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 ...
3
votes
1answer
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} ...
14
votes
4answers
819 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 ...
7
votes
1answer
95 views

Is there something wrong with DistributeDefinitions?

I have the following code, which fails to distribute the DownValues for the symbol f. Could anybody please explain what is wrong. ...
0
votes
1answer
81 views

Subscripts use to make expression readable [duplicate]

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 ...
2
votes
1answer
238 views

Functions without arguments [duplicate]

In the course of a project recently I had to use a particular function u[x, t] a number of times. Because in mathematics I would typically write this function as $...
2
votes
1answer
68 views

Are symbols automatically generated when defining a variable in the global context and what are symbols?

Abstract: I have noticed something really tricky with Mathematica and the documentation for symbols is short on clearing the confusion. It likely reveals what symbols are but it's not very prominent. ...
10
votes
1answer
233 views

How to clear all definitions matching f[1, …] but not f[2, …]?

I would like to clear all definitions of the form f[1,...] in such a way that f[2,...] remain unaffected. The two methods I know ...
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]...
1
vote
1answer
50 views

Simplify terms with delayed and immediate function definitions

Say I want to define a function fwith input x but also involving parameter p not yet ...
4
votes
2answers
61 views

Move definition from one context to Global`

Suppose we have the following package ABC.wl. BeginPackage["ABC`"] Begin["DEF`"] f1 = 0; f2[x_] := x + 1 End[] EndPackage[] ...
8
votes
1answer
92 views

Local variables in sums and tables - best practices?

Stumbled on Local variables when defining function in Mathematica in math.SE and decided to ask it here. Apologies if it is a duplicate - the only really relevant question with a detailed answer I ...
0
votes
1answer
44 views

SetDelayed using local variables

I'm trying to define MakeBoxes for a bunch of functions all at once, but wish to do so within a loop as in the following example: ...
3
votes
1answer
43 views

New variable in With structure appear as global, and many other strange things I don't understand

I thought I know With and Module until I see this example on Wolfram Documentation. Below is a demo code: ...
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....
1
vote
1answer
48 views

syntax error when defining a list of matrices: “…cannot be followed by..”

I am literally just defining a list of matrices, but seem to run into the following error when adding the last matrix. (so to be clear, I get no error when I take out the last matrix entry). What's ...
0
votes
1answer
43 views

Assign variable to solve [duplicate]

I would like to assign my result from equation. I tried /. and := but it gives me empty variable. How can i fix it?
1
vote
1answer
43 views

Getting a stored variable from its value

Given a numerical value, is it possible to check whether that value is stored in (or defines) some variable in the notebook? Maybe if I could list all of the defined variables, then I could simply ...
2
votes
1answer
125 views

Mathematica Won't Recognize a MeshRegion

I've implemented the code in the top answer of this question on the Plateau problem in differential geometry, and it works with the example shown in Example 1, so there is nothing wrong with the code. ...

1
2 3 4 5
9