Questions tagged [replacement]
The replacement tag has no usage guidance.
1,635
questions
0
votes
0
answers
83
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
1
answer
54
views
Testing a condition to replace elements of amatrix [closed]
I want to write a code that checks each element of a given matrix C2 and in case they are't 0 or 1 , replaces them with 1. My code is so far as follows and the code ...
2
votes
1
answer
132
views
Efficiently converting equations into coefficient matrix
I have a list of n linear equations in variables state[i] for i = 1, ..., n and ...
0
votes
1
answer
102
views
Replace two objects in an expression
So I have a long expression that looks like this:
a (e1.e3)^2 (f1.e2)^2 + b (e1.e2)^2 (f1.e3)^2 + c e1.e3 e2.e3 f1.e2 f2.e1 + ...
What I want to do is to replace ...
10
votes
6
answers
352
views
Unexpected output of ReplaceAll
Each week I import a dataset, and every week the dataset differs in length (the number of records). After the import I need to do some transformations. One of these transformations is the ReplaceAll.
...
0
votes
0
answers
34
views
Remove empty TextCell[] from numerical expression
I am evaluating an expression like this:
...
1
vote
1
answer
82
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
3
answers
183
views
Replacing function by another one each time it appears
I have expression involving Cos of some parameters. I would like to replace those Cos by their infinite series each time they do appear.
I tried the following which doesn't work:
...
8
votes
2
answers
237
views
Given x ⊕ x =5,x ⊕ (y ⊕ z) = (x ⊕ y)+z-5 what is 2009 ⊕ 1949
There is an operation "⊕" that satisfies
$x ⊕ x =5$
$x ⊕ (y ⊕ z) = (x ⊕ y)+z-5$
what is 2009 ⊕ 1949?
I think it is feasible to solve with Mathematica, but my code doesn't give a useful ...
0
votes
1
answer
81
views
Change Replace Rule with Function Input
I am trying to create a function that takes in an input $\mu$ and place that input into the replace rule for a numerical integration, as seen in the code below:
...
1
vote
1
answer
194
views
Lévy C curve fractal from a substitution systems in NKS book p.190?
How can I make the geometrical transformation described in the page 190 in the New Kind of Science book by Stephen Wolfram to produce the fractal pattern?
https://www.wolframscience.com/nks/p190--...
1
vote
1
answer
241
views
Substitution of expressions in a symbolic expression
I define tables of symbolic variables in the following form (for convenience)
...
3
votes
2
answers
64
views
Renaming expressions dynamically in Mathematica
I am trying to write a statement that will create a new positionVector as I parse through a matrix.
What I am trying to accomplish would look something like this,
For[i = 1, i <= vectorlength, i++ ...
6
votes
4
answers
580
views
Replace sum x+y+z in expressions like 2x+3y+z
Related threads replacing-a-sum-of-expressions and Replace a sum of squared variables by a new squared variable
Given the identity $x+y+z=p$ I'd like to simplify the generic expression
$$kx+ly+mz$$
...
3
votes
2
answers
327
views
Creating an Array with Subscripts and Superscripts
I would like to figure out how to construct an array using subscripts and superscripts based on the following info:
...
0
votes
0
answers
40
views
Are not rules applied in succession?
I am trying this:
...
0
votes
4
answers
88
views
Only Reals Rules
I have a huge array of rules with many variables, such as
...
1
vote
1
answer
174
views
commutator between tensor products
I am interested in some quantum mechanical calculations in Mathematica. I am working with a tensor product of Hilbert spaces $\mathcal H = \mathcal H_1\otimes \mathcal H_2$. I would like to implement ...
3
votes
1
answer
470
views
Replace in Mathematica [closed]
I have:
$$X=Z+22*Y$$
$$Y=P$$
Edited:
Is there a way to replace $Y$ in the first expression using Mathematica?
I tried Replace and it's not giving the desired result.
Can I replace both Z and Y at the ...
1
vote
3
answers
79
views
My rule does not do anything (understandably)
I want a rule that would transform, for example, And[i,F[j,k],l,G[m,F[j,k],n],p] into And[i,F[j,k],l,G[m,T,n],p], where ...
7
votes
1
answer
217
views
How to replace only the isolated variable x
I want to replace the variable x in the result, not x in unrelated x[i].
...
0
votes
1
answer
70
views
Why does DifferenceRoot evaluate only in this table?
I would like to use a complicated function containing DifferenceRoot as a replacement rule, but somehow it evaluates only in ...
0
votes
0
answers
136
views
How to plot a function using a table particular values
I would like to plot the following function in terms of kR, but using specific different values, I think the best easy way is using a Table. This is a common useful problem to explore numerical the ...
0
votes
1
answer
128
views
Using MapThread and ReplaceAll together
I am trying to carry out some operations on the elements of dataset2, which is an 11 x 14 x 6 dimensional array:
I have a function, ...
0
votes
3
answers
162
views
Pattern matching involving a sum of wildcards
I am trying to implement the following substitution to an expression in Mathematica:
ti den[a-ti] -> -1 + a den[a-ti]
where ...
3
votes
1
answer
346
views
Replace Condition in Replacement Rules
In finding an answer to my other question, I'm finding myself needing to manipulate the conditions imposed on replacement rules, but this is proving to be a little difficult. In particular, how ...
1
vote
1
answer
49
views
When numbers plugged in - this expression evaluates to zero, but otherwise will not evaluate to zero
I have the following code:
...
1
vote
1
answer
135
views
ReplaceAll with a list of parameters [closed]
Trying to ReplaceAll with a list of parameters, but I can't see how to do it properly:
...
1
vote
2
answers
152
views
Extracting subexpressions
This is a recurrent topic: replacing subexpressions. See for instance:
...
2
votes
1
answer
60
views
How to protect the expansion of exponent while applyting rules
I am trying to separate/split an expression (consisting of polynomials) to a list. However I want to keep the exponents intact. Here is an example:
...
3
votes
1
answer
233
views
Mathematica can't replace integer multiple of 2 in power
I have some terms contain
ww=a+a^2+a^6+a^-4
where
(a^2)^p_. -> -dx[p] Exp[-x[p]] x^2
but Mathematica only replace power 2 ...
9
votes
6
answers
760
views
Applying a function to every item in a column of a matrix
A problem that arises more often than I care for is that I want to modify specific elements nested lists.
Examples may be wanting to add 1 to the second value, get ...
1
vote
1
answer
64
views
Why does Replace `/.` not get evaluated in this formula?
Learning the wolfram Language, in section 32
"The Wolfram Language" // Characters[#]& /. Alternatives @@Characters["aeiou"] -> Nothing
...
1
vote
0
answers
62
views
Simplification and patterns
I have a very simple simplification to make, where I need to do a replacement but the pattern matching seems slightly awkward.
I would like to simplify:
...
5
votes
3
answers
213
views
Conditional replacement element-wise
I have a $4\times 4$ matrix (symbolic). It has a variable, say jj, which should be $1$ for diagonal and $0$ for non-diagonal entries. I need to write a replacement ...
1
vote
0
answers
57
views
ReplaceAll with named pattern [closed]
If k is unassigned, this yields {a, b, c}:
...
1
vote
0
answers
63
views
Difference in pattern matching between Cases and ReplaceAll
I don't understand why there is a difference in the pattern matching between
x a /. coef_*x^pow_. :> {pow, coef}
and
...
2
votes
1
answer
72
views
How to get the result in terms of a previously defined expression?
Say I have a vector
X[n_] := Table[Subscript[x, i], {i, 1, n}]
and a matrix of connections:
...
6
votes
1
answer
138
views
How can I get the progressive application of list of rules?
I have a very long list of rules, and using this list of rules I want to see how some elements evolve as I successively apply the next rules on the previous rule.
Here is the simpler version of my ...
5
votes
1
answer
116
views
Turn definitions into rules
I know that this seems to be unnecessary, but here I have a bunch of assignments, like around 50, and I want to create rules for all these to have the freedom to apply these rules only on certain ...
0
votes
2
answers
214
views
How to solve for y for a set of implicit (in x and y) linear equations for use in Plot?
From a matrix m={{1, 1}, {-1, 1}}, a vector b={1, 2}, and a list of variables vars={x,y} we ...
0
votes
1
answer
37
views
Is there a better syntax to obtain the derivative of a function as a function/operator? (e.g. for simple plotting of derivtives of functions, etc.)
When trying to plot a derivative of a function, (I take Sin as a simple example), the naive approach
...
3
votes
1
answer
212
views
Replace multiple variables using a list?
I want to calculate sum of derivatives
of expression
F = Exp[(x*z - 1) f*b + (x - 1) (1 - f) b]
from n-th to (n-k)-th, say k=4. The dummy way which works is:
...
1
vote
1
answer
51
views
Write function in terms of a combined variable [closed]
I am working with recursive convolutions of complex functions (fourier transforms), so, I calculate convolution integrals of functions of the form
$$g(iy) = \int_{-\infty}^\infty f(ix)f(i(y-x))dx, \ \ ...
6
votes
4
answers
251
views
How do I replace specific sequences of a sublist without changing the level of the list?
Suppose I have a list of multiple sublists:
testlist={{1,1,1,0,0,0,1,1,1,0,1,1},{1,0,0,1,1,1,1,0,1,1,1,0}}
I want to replace given sequences without creating new ...
0
votes
0
answers
79
views
How can I shuffle the indices of certain variables?
I am recursively defining rational expressions in two sets of variables $x_i$ and $y_i$. Specifically, for $m<n$, I am interested in replacing all degree-$m$ monomials of the following form: $$\...
1
vote
1
answer
60
views
Error: Root::npoly: not a polynomial in #1 [closed]
I have a $45\times 45$ matrix $H$ and its elements depend on $Ca$. I want to find its eigenvalues (which will also depend on $Ca$). I do this using:
...
1
vote
2
answers
71
views
How to define a series of substituting rules?
suppose I have a long list of many variables: alist = { u, v, w, ... }.
At some point, I have another combination of variables depending on { u, v, w, etc.},e.g.,
alpha = 2 * u + v
beta = v + w^2.
And ...
9
votes
4
answers
518
views
How to use each replacement only once in a list of replacements
I have a list of replacements and some list they are acting on. However, some RHS of the replacements rules are identical (the LHS is not). I want to use those rules one after another (perhaps cycling ...
1
vote
2
answers
44
views
How to match a formula in different level
Solve[4 n^4 + 4 n + 3 == 0]
The result has many
$$
\sqrt[3]{\frac{1}{2} \left(1+i \sqrt{3}\right)}
$$
so I want to replace them with a letter, for example , ...