All Questions
Tagged with replacement expression-manipulation
75
questions
106
votes
5
answers
6k
views
Replacement inside held expression
I wish to make a replacement inside a held expression:
f[x_Real] := x^2;
Hold[{2., 3.}] /. n_Real :> f[n]
The desired output is ...
18
votes
1
answer
607
views
Why is ReplaceAll behaving like this?
I'm learning to use the ReplaceAll function and I found the behavior of which is quite confusing.
For
Sqrt[f[x, y]] /. f[___] -> u
Mathematica returns
<...
17
votes
1
answer
324
views
When is the righthand side of a RuleDelayed evaluated?
The documentation on RuleDelayed states that lhs :> rhs represents a rule that transforms lhs to rhs, evaluating rhs only after the rule is used.
Consider the ...
17
votes
2
answers
952
views
Transform an expression into a graph that can be plotted with TreeGraph (not TreeForm)
I would like to plot an expression (like TreeForm does), but using the new TreeGraph functionality.
...
10
votes
2
answers
1k
views
What is the Difference Between Rule (->) and RuleDelayed (:>)?
I am new to Mathematica so this question may seem rudimentary. Sorry for that! :)
I want to implement the well-known property of Kronecker's Delta
$$\Sigma_{i=1}^{n} a_i \delta_{ij}=a_j,\quad 1 \le ...
7
votes
3
answers
472
views
How to replace $x$ and $x^2$ with different value?
I have an expression now
expr = x + x^2
what I want to do is to replace $x$ with $k\times p$ , and $x^2$ with $[k\times p + k\times(k - 1)\times p^2]$.
The ...
7
votes
2
answers
207
views
Why does my list of positions contain a leading and following element not in the original list?
I have a list which contains non-integers (three in this case) each of which I need to replace with a different Random Variate.
...
7
votes
2
answers
231
views
Efficient Search for specific Terms in symbolic Expression
I have a large symbolic expression with six variables a,b,c,d,e,f per term, roughly like this:
...
6
votes
5
answers
734
views
Manipulating rules
I tried searching in the docs in "Transformation Rules and Definitions", however there wasn't anything of help.
So imagine I have these two rules:
...
6
votes
4
answers
1k
views
Replace all integers by 1?
Let list1 be a list of variables of the form {c1 a, c2 b, ...} where $a,b,...\in\mathbb{C}$ and $c1,c2,...\in\mathbb{Z}$. I am ...
6
votes
5
answers
373
views
First evaluate in place all subexpressions matching pattern before substituting result
ReplaceAll[expr, {patt1:>rhs1, patt2:>rhs2, …}] works by looking for and making all possible replacements of subexpressions in ...
6
votes
1
answer
681
views
Embedding StreamPlot in Graphics3D
I am trying to visualise the action of the infinitesimal generator of a Lie group on the solution of a 2-ODE system drawn in the 3D space (t,y1,y2): t is time and y1,y2 are the two dependent variables....
5
votes
5
answers
442
views
How to subtract these two equations?
There are two equations:
eq1 = x1^2/a^2 + y1^2/b^2 == 1;
eq2 = x2^2/a^2 + y2^2/b^2 == 1;
How to get this result by subtracting two equations?
the result
...
5
votes
2
answers
306
views
Replace a randomly chosen part of an expression
Given an arbitrary Mathematica expression, how can I choose a random part of the expression and replace it with another symbol of my choosing?
For example, given $a x^3 +2y\cos(x)- \tanh(x^{y+3})/(x^...
5
votes
4
answers
1k
views
Replace every Minus to Plus in Expression
Thought this is a rather simple thing, but I was not able to find a solution.
I have a polynomial expression like:
...