Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [replacement]

Questions about Mathematica's rule-based replacement functionality, including functions such as Rule (->), Replace, ReplaceAll (/.) and ReplaceRepeated (//.).

0
votes
0answers
22 views

Replace function for derivatives [on hold]

I have an equation with a partial derivative bzp^(0,1,0,0)[x, y, z, t]. I have solved for bzp[x, y, z, t] from another equation, ...
0
votes
0answers
32 views

Could not able to replace some terms in my final expresion

I have three equations. The third one is the sum of the first and the second. I wanted to replace some terms in the third equation but it is not happening. I don't know why ...
0
votes
5answers
47 views

Expressing D[1/D1, x] in terms of D1 when D1 = 1 + x

For simplicity, taking D1 to be equal to 1 + x, I want to evaluate the derivative of 1/D1 (...
3
votes
1answer
126 views

Pattern test: _Integer vs _?IntegerQ [closed]

While checking out the different pattern replacement methods in this question, I have a query regarding the basic difference between the following two replacements: ...
1
vote
1answer
33 views

Using rule with derivative

Assuming I have an expression like: D[a[t, r], r] + D[D[a[t, r], r],r] + D[D[a[t, r], t],r] I would like to change variables, by expression everything in terms of ...
0
votes
1answer
55 views

How to substitute integral operators into polynomials?

Suppose I have a polynomial $a_0+a_1 f(x,t) + a_2 f(x,t)^2 + ....$. In code, a0 + a1 y + a2 y^2 + a3 y^3 /. y :> Integrate[Subscript[y, k] E^(I k y), k] <...
1
vote
1answer
253 views

Replacement using pattern matching?

Starting with the expression eq1 = 5 Exp[1 + 2 x + 3 x^2 + 4 x^3]; I want to implement the following transformation: ...
2
votes
1answer
62 views

Pattern matching failed [closed]

I want to replace Θ[z + m τ] by a[m] Θ[z]. So I consider the pattern ...
1
vote
0answers
49 views

How to replace an expression in an entire notebook?

I have a frequently occurring complex expression, let's for simplicity say $a+b$ which I want to replace with let's say $c$ in all the mathematical expressions following this Rule. It is simply like ...
0
votes
0answers
28 views

How to replace all the derivatives of a particular function?

For a given expression, such as: exp=p[x]+p'[x]+p''[x]...Derivative[n][p][x] I want to replace all the derivatives of p[x] to ...
1
vote
1answer
15 views

Show result of matrix operation in terms of user defined matrices

I have defined some matrices K[0],K[1],...,K[9] and S[1],...
0
votes
1answer
80 views

Substitution into integral [duplicate]

I have to do a substitution (u = pi/2-x) into an definite integral, which I have defined as f[u]. When I evaluate my code, no ...
1
vote
1answer
49 views

Replace second derivative with product rule

Suppose that after some calculations, I find a[x]*D[g[x],x,x]+b[x]*D[h[x],x,x]+c[x]*D[j[x],x] What sort of operations do I need to do in Mathematica such that ...
0
votes
1answer
29 views

Substitution of an expression into another expression

I'm trying the following Mathematica command to simplify an expression by substitution of a known constant, but it's not performing the substitution. Any ideas why? ...
1
vote
1answer
62 views

Replace every n-th part of list [closed]

I have a list: b = ConstantArray[1, 50]; And I would like to replace every say 5th element with 2: I came up with: ...
6
votes
2answers
543 views

How to use ReplaceAll on an expression that contains a rule

I know I have seen this before but can't seem to locate it today. I am trying to take an expression that has some rules in it and replace one of that parts that contain a rule using ...
2
votes
2answers
62 views

Replacing with pattern on built-in symbols?

I have: f[a, b] /. f[x__] -> g[x, 0] // InputForm (* Out: g[a, b, 0] *) Which is what I expect, but when I use a built in symbol instead of ...
0
votes
1answer
70 views

Replace expressions outside certain functions

I'm trying to replace variables outside of certain functions. More precisely, in the standard ones like Sin substitution should work while in undefined ...
1
vote
1answer
37 views

Replacing with Elements from a List [duplicate]

I have a fairly complicated expression with nested lists and I want to substitute a given string for each integer. Here's a simple example where ind is my integer-valued data structure and names is ...
1
vote
0answers
23 views

Moving to the last placeholder with inputautoreplacements

I have had a long-standing problem when I try to use my inputautoreplacements in a text cell. The replacements I have made include boxes that include placeholders. When in the text cell, you type ...
4
votes
1answer
98 views

A single argument pattern definition applies to multiple-argument patterns?

Consider defining a pattern rule, such as myFun[x_]:=x As far as I understand Mathematica syntax, this rule means ...
1
vote
3answers
110 views

Substitution in expressions

As the title suggests, I want in an expression to to some substitutions. For example in the expression $\mathcal{L}^+_0+\mathcal{L}^-_0+\mathcal{L}^+_0+\mathcal{L}^-_0+\mathcal{L}_1$ I want to ...
0
votes
1answer
48 views

Replacing a derivative [closed]

If I want to calculate e.g. $\frac{dr(t)}{dt}$ then in Mathematica we can write e.g. , answer = D[r[t],t] This outputs r'[t] ...
0
votes
1answer
37 views

constructing Matrix from coefficients of solution & assigning 0 for empty Cells [closed]

i tried to construct a matrix from the coefficients of my solution, but problem that; 1; how can i get coefficients out of Solve 2; some Matrix elements are empty so i must assign 0 in those empty ...
0
votes
1answer
51 views

Replace constant in summation function using replace or If or /

Hi i how do i replace constant for k in this summation. For following: Even 2*n Even replace k by a Even 2*n+1 Odd replace k by b Here is the code ...
5
votes
1answer
60 views

Inconsistent application of replacement rule

I want to use a replacement rule to change log[var] into var inside a function. A minimal example follows. In one case it ...
4
votes
2answers
93 views

Finitely many repeated replacements

I'm looking for good practices to replace a given function recursively n times by itself with its arguments. The following example (for n=2) hopefully makes it clear: ...
0
votes
1answer
59 views

Using the Replace function [closed]

How can I replace two variables at once with Replace[] ? Can't find how to do this. I tried Replace[x^2+y^2, {x -> a, y -> b}] but does not work...
7
votes
2answers
131 views

Replacement Rule for Functions

Attempting to write a rule that will substitute an undetermined function of several variables by some other undeterminate functions (also, of the same several variables). I can do it in an inelegant ...
2
votes
3answers
151 views

How to avoid Replace substituting subscripts?

I have a polynomial in $\rho$ with many parameters (I will omit the polynomial code in the Mathematica expressions below because it is too long): $$ \rho ^3 J (\mu +1) \left[(A \delta \tau _0+B (1-\...
0
votes
1answer
40 views

Substitution inside an expression [duplicate]

I'm trying to get mathematica to replace an expression with a reduced form. I wanted to replace $(k/w)$ with $h$ in a particular expression, and I've tried something like: ...
5
votes
1answer
237 views

Neglect higher order derivatives in expression

Say I have an expression of this sort: Derivative[5][x1][t]+Derivative[3][x2][t]+x1[t]+Derivative[2][x1][t] and so on... I would like to ask Mathematica to ...
1
vote
2answers
51 views

Replacement rule for terms that are separated by operators?

My main problem is how one can create a "transcending between operators rule" in the same term according to the minimal example bellow. Suppose I need to perform a replacement of the form ...
1
vote
1answer
45 views

Question about replacement and plot

I want to plug a value into the following solution which I defined. ...
1
vote
3answers
58 views

How to apply a continious substitution reduction of (-1 + 3 phi - 2 phi^3 - 6 phi^4 - 20 phi^6 + 6 phi^7 + 3 phi^8 + phi^9)//.{phi^3->1-phi^2}

I have the answer to $(-1 + 3 phi - 2 phi^3 - 6 phi^4 - 20 phi^6 + 6 phi^7 + 3 phi^8 + phi^9)/.{phi^3->1-phi^2}$, that is not the problem. I am looking for a method that continues to apply this ...
4
votes
1answer
205 views

Setting Some Elements in a Matrix to zero

Assuming I have the a 5x7 matrix below: b = ((1, 4, 9, 16, 25, 4, 2), (36, 49, 64, 81, 100, 5, 1), (121, 144, 169, 196, 225, 8, 9), (256, 289, 324, 361, 400, 9, 5), (441, 484, 529, 576, 625, ...
2
votes
2answers
70 views

Elements Replacement

Please I need help on how to replace elements in a matrix with another elements. For example, I have a (5,5) matrix, and I like to replace elements from All rows and column 3 to 5, with zero. such ...
2
votes
1answer
122 views

Notation package with Traditional Form

I symbolize subscripted variables with the form TraditionalForm, to enable easy use of TeXForm as suggested here: ...
1
vote
2answers
37 views

Replacing a subset of variables in a polynomial [closed]

Let's say I have a polynomial in n variables, e.g. x^3 + xyz + z^2, where n=3 in this case. How can I replace all of the variables in the equation with a certain number? I tried things like ...
1
vote
2answers
42 views

Replacement rule for a function and its derivative

I have this equation: EOM1 = Subscript[x1, t, t] + ω1^2*x1 /. Subscript[x1_, m__] :> D[x1[x, t], m] /. x1 -> x1[x, t] The problem with the ...
1
vote
1answer
85 views

Convert String in Expression to Integer

I have reviewed many string replacement Q&A but I have been unable to apply them to this case (MWE): ...
2
votes
0answers
28 views

Using Min & Max of an Interval in a replacement [closed]

I want to use a replacement rule to transform a list of equations. The following works as expected: ...
3
votes
2answers
102 views

Convert defined variables to rule list

I'd like to make a function that takes a list of variables and returns a corresponding rule list with the current values of the variables. E.g. ...
1
vote
0answers
45 views

Why doesn't `ReplaceAll` work in this situation? [closed]

I can work around this by using With, but it seems really odd to get the following: ...
2
votes
3answers
49 views

Using rule output as function

Im trying to define a function using the output from RSolve, however i cant get it to work properly. I have a RSolve that output something like: ...
1
vote
2answers
67 views

Having problems with using TableForm to format a table

I want to make a table of various values of the logistic curve given by l[x_] := 1/(1 + E^((-k)*(x - \[Alpha]))). In basic form, this is dead easy. However, I want ...
1
vote
2answers
71 views

Why does this replacement rule for imaginary unit not work? [closed]

I'm trying to replace imaginary unit in an expression with a real unit: E^(-I y) /. I -> 1 E^(-I y) As you can see, in ...
1
vote
1answer
41 views

ReplaceAll giving different answer than actual replacement

I have an expression, and I wanted to evaluate it for a certain value of a variable. However, /. gives a calculation error, whereas manually replacing the variable with the value succeeds. Why? $$\...
1
vote
3answers
74 views

How to make functional rules not depend on an argument?

Consider the following: rule = f[x] -> Sin[x] if I now do, say: f[y] /. rule this does not work, because the rule wants ...
1
vote
1answer
22 views

Merging values of a list of rules where some keys occur more than once

I have a list of rules resembling rules = {{a -> {1, 2, 3}}, {b -> {2, 3, 4}}, {c -> {3, 4, 5}, c -> {4, 5, 6}}} How can I neatly rearrange this to ...