Skip to main content

All 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 ...
Alexey Popkov's user avatar
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 <...
user2256793's user avatar
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 ...
Fred Simons's user avatar
  • 10.2k
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. ...
scaramouche's user avatar
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 ...
Hosein Rahnama's user avatar
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 ...
Yuejiang_Li's user avatar
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. ...
Rogo's user avatar
  • 940
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: ...
Mario Krenn's user avatar
  • 2,182
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: ...
Confuse-ray30's user avatar
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 ...
Kagaratsch's user avatar
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 ...
QuantumDot's user avatar
  • 19.7k
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....
pdini's user avatar
  • 485
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 ...
csn899's user avatar
  • 4,521
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^...
flinty's user avatar
  • 25.6k
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: ...
Mario Krenn's user avatar
  • 2,182

15 30 50 per page
1
2 3 4 5