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

learn more… | top users | synonyms (4)

3
votes
1answer
26 views

Possible incompatibility between ReplaceAll and LaplaceTransform

I have a large symbolic expression containing many terms of the form, LaplaceTransform[u2[z], z, s], with various functions for the first argument. I wish to ...
0
votes
1answer
66 views
1
vote
0answers
31 views

How Can I combine the equations' results in a table without “x->” [closed]

For example: I have a series of functions: F[x_,o_]=x+o And I want to combine the result into a table with o=0.3,0.6,0.9.. ...
5
votes
5answers
210 views

Converting set of characters into numbers using list of replacement rules

I am trying to convert a text, as an example "aaaa" into a set of numbers as defined in a list of replacement rules, for example letterstonum . letterstonum takes in letters a to z and returns the ...
0
votes
1answer
35 views

Replacement of a group of variables in trigonometric expression

I would like to make simplification of trigonometric expressions by using a replacement a group of variables. Here the equation I have to simplify : ...
0
votes
2answers
59 views

replace a part of equation by a symbol

I have an equation: $$ \frac{d\text{$\phi $0}}{dx} \left(-\frac{\text{A1}(x) \frac{d\text{A0}}{dx}}{\text{A0}(x)^2}+\frac{\frac{d\text{A1}}{dx}}{\text{A0}(x)}+\frac{\text{B1}(x) \frac{d\text{B0}}...
4
votes
2answers
103 views

How to put replacement rules into a package

I have a replacement rules list, but its quite long and therefore I would like to make a standalone package of it. I tried but haven't succeeded. A simple example of my approach is ...
1
vote
1answer
59 views
5
votes
1answer
108 views

How to make a postordered ReplaceAll that operates just once per subtree?

The answers to this question provide code for a function I'll call postOrderReplaceAll to replace from the inside-out: ...
1
vote
0answers
52 views

A kind of function optimization problem [duplicate]

I have the following problem. Out of a calculation I got the four functions shown at the end of the post. These functions depends on many variables, qk, pk etc (all of them are actually scalar ...
1
vote
3answers
266 views

How to select elements from a list by condition?

Considering I have a list: F = {f1, f2, f3, f4} I want to perform exponent on the list F = Power[#, 2]& /@ F Now I ...
11
votes
2answers
99 views

Replace and Association

I'm surprised that I can't find this question already, so perhaps I'm missing something obvious. I would like to take a list of associations and remove any with value ...
1
vote
2answers
61 views

Using a rule to increase precision [closed]

I'm sure this is a very simple question, but I can't work out how to do it. Construct a rule to set x=0.32 to a precision of 20 digits. The rule is to be applied ...
4
votes
2answers
122 views
0
votes
0answers
27 views
3
votes
2answers
76 views

Replacing symbol with vector

Consider example: expr := {-1, 1} * value expr /. {value -> {10, 20}} (* {{-10, -20}, {10, 20}} *) however, I expect to have something like ...
3
votes
2answers
39 views

Setting initial conditions of a domain grid?

So I'm writing some code to try and produce a cellular automaton which will model an oscillatory chemical reaction, but I'm trying to set up the initial conditions of the grid so that I can vary them ...
1
vote
0answers
36 views

replace a^2 and b^2 with a different rule to ab [closed]

I have an expression and need to replace all instances of $x^2$ with $a$, all instances of $y^2$ with $b$ and all instances of $xy$ with $0$, but I only know how to replace $x$ or $y$ individually. ...
0
votes
1answer
52 views

Filter pattern from a list

I have group elements, that I'd like to condense down according to group rules. Take the modular group. This has generators $S,T$ that satisfy the groups relations $S^2 = I, (ST)^3 = I$. So given a ...
0
votes
1answer
59 views

Rule for multiplying of Kronecker-delta-type functions

I am trying to introduce a rule of multiplication of entries of a matrix which would have the following property: delta[k,i]*delta[k,j]=delta[k,i]*delta[i,j] and ...
1
vote
1answer
48 views

How to substitude a^n->D[u[t,x],{x,n}] for n=0,1,2,

I have expression which have terms a, a^2, a^3, ..., How can I replace a^n -> D[u[t,x],{x,n}] for n=0,1,2,....
1
vote
1answer
77 views

Why does using replacement rules give a different result than setting the variable? [duplicate]

These two methods should give the same result, but one terminates when the result is unchanged (to machine precision) while the other continues for the full 100 allowed cycles. Why? ...
7
votes
1answer
185 views

Remove leading and trailing zeros from a list

This functions and gives the desired result: {1, 0, 2, 0, 0} /. {x___, 0 ...} :> {x} {1, 0, 2} But with leading zeros it doesn't: ...
0
votes
1answer
57 views

Issue with replacement rules screwing up a matrix [closed]

I am pretty new to using Mathematica as more than a calculator. Essentially my problem is that I am trying to calculate a quantity vector quantity $x=x_0 - A^{-1}F(x_0)$ where $x_0$ is a 3-entry ...
4
votes
1answer
89 views

Why a part of this expression, similar to another, is left unchanged?

An expression has one of its part replaceable and one, strictly similar, that isn't. Please, can you point at the difference ? I can't pinpoint the complication ... The FullForm of ...
12
votes
2answers
292 views

why MatchQ is fast and Replace slow?

Consider a large expression, say a polynomial with 25 terms expr=Product[Unique["a"],{i,1,25}]; to which you apply the following replacement rule: ...
1
vote
2answers
95 views

Symbolic derivatives and substitution [duplicate]

I have troubles substituting functions when I have symbolic derivatives and I need to substitute more symbolic derivatives in my expression. Take for example ...
5
votes
3answers
184 views

How to replace an element in a list with an element in another list with matching indices

I have a list like this l = {1 + 2*s, 2 + 3*s, 4 + 1*s}, and I have calculated s = {1, 2, 3}. I need to replace ...
7
votes
1answer
119 views

Using two rules for the same variable

I am a newbie in the field so please not angry. I am reading the tutorial below and having a problem. Link: How to Create and Use Rules From the link: If you give two rules for the same ...
2
votes
2answers
71 views
3
votes
1answer
50 views

Replacing elements of a matrix

I'm trying to write a program that takes a given matrix $A$ of 1's and 0's and flips a designated amount of 1's to -1's. ...
3
votes
2answers
69 views

Assigning multiple solutions different replacement names

Let's say we are solving a homogeneous differential equation, such as $$y^{\prime\prime} + a y^{\prime} + b y = 0$$ with characteristic equation $$s^2 + a s+ b = 0.$$ Using the ...
6
votes
2answers
102 views

Condition and RuleDelayed

On this site I found, for example here, some very interesting questions and answers on the use of delayed rules with conditions. I would very much like to understand these answers, but so far I failed ...
8
votes
2answers
120 views

Why is a longer pattern matched rather than a short pattern?

I was reading the Mathematica V5 Book and am a bit perplexed on the behavior of a particular pattern matching example where it seems to be choosing a longer pattern rather than a shorter pattern. The ...
0
votes
0answers
25 views

Simplifying self-reciprocal rational function [duplicate]

I have trouble transforming self-reciprocal rational functions in one variable like ...
5
votes
3answers
100 views

How can I pass replacement rules to a package-defined function and have it understand their context?

I am writing a package where I would like to be able to pass replacement rules to a function inside the package and have the function manipulate its symbols using those replacement rules. However, I'm ...
1
vote
1answer
62 views

how to replace one calaculation result to another one in a loop?

I am doing the calculation in a loop. I gain a digit for rzin in ...
14
votes
3answers
232 views

ReplaceAll with Associations instead of Rules

I have just noticed that x /. <|x -> 123|> evaluates to 123 In other words, the association seems to behave as a ...
1
vote
3answers
125 views

Symbolic differentiation [closed]

I have two symbolic differential equations and I want to used them in another equation as follows: ...
2
votes
1answer
43 views

ReleaseHold NIntegrate after Replace variable

I would like to calculate the sum of square of two integral(Ex and Ey). I first hold this two integral because two variables(tx, ty) are not specified.Then, I replace tx,ty and releasehold $Ex^2+Ey^2$....
0
votes
0answers
58 views

How do I use Replace All? [duplicate]

I have an expression: a + b 2^(1/2) + (c + d 2^(1/2))*I I want to replace each occurrence of 2^(1/2) with ...
2
votes
1answer
72 views
3
votes
1answer
34 views

TensorContract with KroneckerProduct instead of ordinary Times

Is it possible somehow to contract two tensors, say A={{a1,a2,a3},{a4,a5,a6}} and B={b1,b2,b3}, where the elements ...
9
votes
1answer
172 views
2
votes
1answer
121 views

Function not returning number [closed]

I am quite new to Mathematica and I guess this question is really basic, but I can't figure it out myself. I'm making a simple notebook that plots a Hamiltonian function, a plane of constant energy, ...
0
votes
0answers
57 views

Can't operate on vector within a list of rules

I'm trying to set up a list of rules which includes the following: ...
0
votes
2answers
45 views

Unevaluated derivatives of known functions after replacement

I want to make the following replacement work correctly: Array[(2 D[xM[[#1]][t], t] * D[xM[[#2]][t], t]) &, {3, 3}] /. {xM -> {Sin[ω t], Cos[ω t], 0}} ...
5
votes
2answers
487 views

Replace rule with function? Derivatives don't evaluate

Say I have an expression (call it expr) involving a function, f[x]. I'd like to be able to evaluate that for a particular choice of ...