Questions tagged [replacement]
The replacement tag has no usage guidance.
1,594
questions
0
votes
0
answers
48
views
ParametricNDSolveValue as replacement rule [closed]
I have a system of 4 non linear differential equations x[t],y[t],z[t],w[t]with one free parameter a solved with ...
7
votes
1
answer
161
views
Can you explain this substitution rule?
This rule behaves as I expect:
b . c + a . b . c /. (b . c) -> x
(* x + a . x *)
I would expect the same result with this:
...
3
votes
4
answers
204
views
Different answers when attempting replacement of function argument
I have three function computing Fibonacci numbers which return correct answers when directly called with e.g. fib1[10]:
...
4
votes
5
answers
306
views
How to make ReplaceAll recognize what to be replaced in a situation like this?
I'm a bit confused on how ReplaceAll works. For example
ReplaceAll[2x+2y, x+y -> 1]
just gives ...
2
votes
1
answer
51
views
ReplaceAll that works inside Rational?
I'm trying to replace all instances of a 31632259 in a formula with x, but there's something special about how Mathematica ...
4
votes
3
answers
145
views
With function replace rule does not work in
If I define an expression , and evaluate it in With function, replace rule does not work.
sumT = TA + TE;
With[
{TA = 0.1, TE = 0.2},
{TA + TE, sumT}
]
output
<...
0
votes
0
answers
37
views
Simplifying symbolic expression using replacement rules
I am trying to carry out a linear stability analysis of a two PDE system. I start by defining the equations and then define the perturbation along with the replacement rules required. I then use a ...
1
vote
1
answer
62
views
ReplaceAll causing infinite recursion
I have two expressions
expressionA = (-B*a + b)/M
expressionB = (-A*c + d)/M
expressionA depends on ...
0
votes
2
answers
75
views
Same code behaves differently as a pure function and a function, and insider another function
I have a rule-transformer that takes a list of rules (and a list generator = {σ[z], σ[-1], σ[1]})
...
0
votes
1
answer
40
views
Transform a list of delayed rules with conditions to a new list of delayed rules
I have a list of rules that implement some abstract algebras, for instance, that of the Pauli matrices,
...
4
votes
1
answer
112
views
How to force Mathematica to simplify in terms of half angles?
By basic trigonometric identities, the expression $\frac{\sinh(x)}{\sqrt{2}\sqrt{1+\cosh(x)}}$ simplifies to $\sinh(\frac{x}{2})$. But Mathematica seemingly don't perform this simplification. I tried ...
0
votes
0
answers
40
views
RuleDelayed with Simplify?
I have the Rule
yRule = y -> Function[{l,m,x},x^(l + 1) Exp[-((2 I m)/x)] Hypergeometric1F1[1 - l, -2 l, (2 I m)/x] ]
Is it possible to replace and simplify ...
5
votes
1
answer
202
views
How to Replace 'delta t' with 'a' in Mathematica Without Affecting Separate Instances of 'delta' or 't'?
In Mathematica, how can I replace instances of delta t in an expression with a, while keeping instances of ...
0
votes
1
answer
58
views
Why is replacement so slow for long sums?
I have an integral of a sum of many terms:
$\int \int S_y^2 a a^\dagger f_1(t_1)f_2(t_2)^* + ...$
For example
...
7
votes
6
answers
484
views
Apply function to all first arguments of a nested list of rules
Currently, I have a nested list of rules of the form
lst1={1->a,2->{3->c,4->d,5->{6->f,7->{8->h,...}}}}
(where I don't know the length of ...
2
votes
2
answers
116
views
Convert list of variables to list of parametrized functions
I have a list of differential equations of some variables
eqns = {f[x,y,x',y'],g[x,y,x',y']}
e.g., f[x,y,x',y'] = x x' + y y'. ...
0
votes
1
answer
62
views
Replacement of a combination of parameters with a single parameter [closed]
Suppose we have the equation 1+u/(L $\omega$) and we want to replace L $\omega$ / u with Da such that this yields the new equation 1+1/Da.
Is Mathematica able to do that?
...
1
vote
1
answer
81
views
Applying matrix commutation rules
I want to symbolically replace occurences of matrix terms such as $zAB-zBA$ with $zC$, where $z$ is a number. This works as expected:
...
0
votes
1
answer
58
views
Syntax error trying to rewrite expression using rules
I want to use Mathematica to calculate derivatives of some long, complicated expressions. I have an integral with integrand $I_*$ which is a functional that depends on $h(x,t)$ and $\phi(x,t)$. The ...
1
vote
2
answers
206
views
Simplifying products of DiracDelta
I want to simplify expressions containing DiracDelta products. For example I want to simplify the expression
$$\delta(z-2)\delta(k-5)\delta(t-z-k-9)$$
to give the answer
$$\delta(z-2)\delta(k-5)\delta(...
2
votes
3
answers
137
views
Replace only some instances of a symbol in an expression depending on what it's multiplying it
I have an expression of the type
expr = k*a + j*a + a*f + a*g + h
And I would like to set a=0 but ONLY if it's NOT multiplied ...
3
votes
4
answers
1k
views
How to replace many functions with the form of "f(n+k)" into "f[n+k]"?
I found a problem that I cannot solve. When I copied a recursion created in MAPLE into a Mathematica Notebook, I found the form of the function in MAPLE is different than Mathematica.
The difference ...
1
vote
0
answers
57
views
How do I efficiently define rules for non-commutative algebras, (like differential forms)?
Defining rules seems to be quite troublesome, because whatever rule I make has to have the exact syntax ordering of the expression I want to modify.
For example,
take this differential form
...
5
votes
2
answers
210
views
Crafting a replacement rule to convert derivatives to finite differences
I need to construct a replacement rule to replace (first) derivatives with centered finite differences. What I've got so far is
...
2
votes
1
answer
87
views
How can I use UpSet with a derivative value?
I'm trying to UpSet a certain value for the derivative of a function $Y=Y(l,m,x)$.
This can be done by:
...
2
votes
1
answer
35
views
StringReplace with Style will cause another character in the string [duplicate]
StringReplace["abbaabbaa", "ab" -> "X"] will output XbaXbaa, but ...
3
votes
7
answers
434
views
Function to replace values of elements of matrix with 0 unless the value is -1
How can I write a function that replaces all the elements of a matrix with zero unless the value is -1?
1
vote
1
answer
57
views
3
votes
1
answer
114
views
Force `Simplify` to use half angle identities?
How do I force Simplify to use half angle identities?
Suppose I have (x is in the Reals)
...
1
vote
2
answers
100
views
Replacing Kronecker delta times expression with the expression with inserted index
Consider the following symbolic expression:
expr = f[a,b]*g[c,d]KroneckerDelta[a,m]KroneckerDelta[d,k] + KroneckerDelta[a,p]f[x,a]+const
Could you please tell me ...
3
votes
1
answer
132
views
How to assign the following rule?
Consider the following object: function[x,a,b]. It is a symbol carrying one "coordinate" x and two indices a,b.
I ...
3
votes
2
answers
381
views
Why the replacement rule works okay for scalars but not okay for matrices?
Consider the following UpSetDelayed:
D[Kstar0[x_, a_], x[b_]] ^:= dKstar0[x, a, b]
It works fine if applied to a scalar ...
2
votes
0
answers
54
views
Replace in matrix at given indices [closed]
How to replace a term at defined indices of a matrix?
The expression
{{a, b, c}, {a, b, c}} /. c -> d
replaces both c but for this example I want to replace only ...
3
votes
2
answers
188
views
Replace a column/row of a matrix under a condition by a random number
Lets say there is a matrix of the form:
matrix = {{1,2,3},{4,5,6},{7,8,9}}
I want to replace the elements of the last column, if they are larger then zero, by the ...
2
votes
1
answer
93
views
How can I change entries in a list of lists depending on the entries in the list itself?
I have an 3D dimensional Array of data. It has this kind of strucuture: {i,x,y}
...
0
votes
0
answers
37
views
Issue with piecewise functions and lists of rules
I have a list of data that I am connecting with a simple piecewise function. I then want to evaluate the piecewise function at a different list of points. I can do it the long way, but I am wondering ...
1
vote
1
answer
69
views
Multiple pattern replacement rule in Mathematica
I am trying to replace the following expression with the definition $A[m,n]=\frac{1}{k^ml^n}$. The expression is $W=\frac{1}{k}+\frac{1}{kl}$. So it should give $A[1,0]+A[1,1]$. So I need two ...
0
votes
0
answers
44
views
Define or remove a long form input \[xyz]
There are "InputAliases" ⵗxyzⵗ, "InputAutoReplacements" xyzspace, and things we'll call "long form inputs" \[xyz]. It's easy to view and modify the former two ...
5
votes
9
answers
387
views
Rotate elements in a list using a for loop
I have the following list.
data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
I want to replace (rotate) each element using a for loop. In the first step, the first element ...
3
votes
2
answers
76
views
Replacing expression
My goal is to make expression simpler using Replace funcion with the assumption; $$ (1+x)^n \approx 1+n x $$
The expression at the nominator was replaced as expected, but the expression in the ...
0
votes
0
answers
75
views
Replacing something in an expression
I have an expression as follows:
expr = K*ComplexExpand[Abs[f]^4] +
P*D[(ComplexExpand[Conjugate[f]] // TrigToExp), x]
where f is a function with two ...
0
votes
0
answers
29
views
Stack Solve solutions in a loop [duplicate]
I want to solve the following equation in a loop:
...
2
votes
2
answers
74
views
Error with using ReplaceAll
I wrote a For Loop. In this For Loop, I want to change the values of a list. The main issue is:
I have a nested list like:
...
3
votes
2
answers
144
views
Keep Log10[] in result
I want to work using Log10[...] yet it keeps reformatting to Log[...]/Log[10].
This simple example can be avoided by using ...
2
votes
1
answer
49
views
Replace coefficients with RootApproximant of themselves
I have an expression, not necessarily a polynomial, and want to take all the coefficients on whatever terms there are and replace them with the RootApproximant ...
4
votes
2
answers
259
views
Displaying integrals with non-variable factors in front [duplicate]
In class I sometimes go through the steps in mathematical derivations using Mathematica. Some of the steps involve substitutions and assumptions that come conceptually outside a strict mathematical ...
0
votes
1
answer
27
views
Replace part of output and simplify it
I have a code that give me :
E^(k (k n + (B - A k) HarmonicNumber[n])) (1 - r)^n
Now I want to replace HarmonicNumber[n] with:
...
1
vote
0
answers
48
views
Why do rules not default to local scope? [closed]
Consider the following:
80 //. a_?EvenQ -> a/2
a = 3
80 //. a_?EvenQ -> a/2
which outputs:
5
3
3/2
I think I understand ...
0
votes
1
answer
47
views
Resubstituting variables back into the calculated
I have lengthy second order derivative of a function that is defined with multiple lines of variables. When I compute the derivative how can I put back into the computed result the auxilary variables ...
0
votes
1
answer
37
views
Substituting variables into an implicit equation and then plot it
I tried this:
ContourPlot[(4-d^b==0)/.b->1/t, {t,0,1},{d,0,4}]
However, nothing is plotted. This works fine instead:
...