Questions tagged [replacement]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
0 answers
82 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: ...
mikado's user avatar
  • 16.1k
3 votes
4 answers
203 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]: ...
youyou's user avatar
  • 123
4 votes
5 answers
304 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 ...
user1620696's user avatar
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 ...
Yaroslav Bulatov's user avatar
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 <...
eason's user avatar
  • 197
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 ...
Mjoseph's user avatar
  • 221
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 ...
FlavonBSM's user avatar
0 votes
2 answers
74 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]}) ...
Lelouch's user avatar
  • 513
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, ...
Lelouch's user avatar
  • 513
4 votes
1 answer
110 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 ...
Sanjana's user avatar
  • 43
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 ...
Nitaa a's user avatar
  • 698
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 ...
Tokubara's user avatar
  • 215
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 ...
Luca's user avatar
  • 83
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 ...
cstover's user avatar
  • 323
2 votes
2 answers
115 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'. ...
Joalito's user avatar
  • 123
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? ...
erhue's user avatar
  • 11
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: ...
Yashman's user avatar
  • 13
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 ...
Mjoseph's user avatar
  • 221
1 vote
2 answers
203 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(...
Mohamed Mostafa's user avatar
2 votes
3 answers
136 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 ...
Bibliotebarbarian's user avatar
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 ...
zyynankai's user avatar
  • 133
1 vote
0 answers
56 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 ...
ions me's user avatar
  • 761
5 votes
2 answers
207 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 ...
Chris K's user avatar
  • 19.5k
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: ...
Nitaa a's user avatar
  • 698
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 ...
Y. zeng's user avatar
  • 425
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?
Nicola Gambaro's user avatar
1 vote
1 answer
57 views

Why the first is evaluated while the second is not (Sum behaves differently from Integrate)?

...
Anixx's user avatar
  • 3,553
3 votes
1 answer
113 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) ...
ydd's user avatar
  • 3,453
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 ...
John Taylor's user avatar
  • 4,642
3 votes
1 answer
131 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 ...
John Taylor's user avatar
  • 4,642
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 ...
John Taylor's user avatar
  • 4,642
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 ...
granular bastard's user avatar
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 ...
100xln2's user avatar
  • 427
2 votes
1 answer
91 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} ...
100xln2's user avatar
  • 427
0 votes
0 answers
36 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 ...
Claudia's user avatar
  • 31
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 ...
Tanmoy Pati's user avatar
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 ...
Adam's user avatar
  • 3,897
5 votes
9 answers
386 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 ...
Michiel van Mens's user avatar
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 ...
Soon's user avatar
  • 359
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 ...
HD239's user avatar
  • 543
0 votes
0 answers
28 views

Stack Solve solutions in a loop [duplicate]

I want to solve the following equation in a loop: ...
Syn1110's user avatar
  • 51
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: ...
Michiel van Mens's user avatar
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 ...
Andrew Malcolm's user avatar
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 ...
D. Brown's user avatar
  • 304
4 votes
2 answers
256 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 ...
David G. Stork's user avatar
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: ...
caren's user avatar
  • 115
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 ...
Jonah's user avatar
  • 121
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 ...
Al Guy's user avatar
  • 1,580
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: ...
Ulysses Zhan's user avatar
1 vote
0 answers
41 views

Evaluate coefficients of delta functions in a given expression

Suppose that I have a function of the form: myfn[x_] = smoothfn[x] + A[x] DiracDelta[x-x0] + B[x] DiracDelta'[x-x0], where ...
Patrick.B's user avatar
  • 1,359

1
2 3 4 5
32