# Tag Info

### Replacement of a variable only for a part of an expression

You may either use ReplacePart (close to what @Alrubaie proposed) expr = a^2 + f[a]; ReplacePart[expr, 2 -> f[c]] (* a^2 + f[c] *) or map the replacement ...

### Replacement of a variable only for a part of an expression

You just need ReplacePart Where ReplacePart[Function/Expression , Location which part to replace] ...

### How to replace anti diagonal elements of a matrix

Making use of the method posted by ciao (in an answer to How to zero (or replace) the diagonal of a square matrix?) ...

### How to replace anti diagonal elements of a matrix

idm = IdentityMatrix[Length@m] (res = Reverse /@ (m idm) + m (-(Reverse /@ idm ) + 1) ) // MatrixForm \left( \begin{array}{ccccc} 100 & 9 & 3 & 8 &...

### How to replace anti diagonal elements of a matrix

use element-wise operation. keep the diag-matrix and reverse it. anti = mat // Diagonal // (*take diag*) DiagonalMatrix // (*make mat*) Map[Reverse] (*rev it*) {...

### How to replace anti diagonal elements of a matrix

We can subtract the anti-diagonal to remove it and then add the Reverse of diagonal. ...

### How to replace anti diagonal elements of a matrix

From The Procedural Dodo: If you can do it in place (destroying the orginal m), this will be fast: ...

### How to replace anti diagonal elements of a matrix

Using ReplacePart: ...
Accepted

### How to replace anti diagonal elements of a matrix

This is the kind of question that might trigger the "how-many-ways-can-you-do-it" game. I'll kick it off with this: ...

### 'Mapping' the values of a list to variable

Different way: expr1 = a[n] + b[n] stencil = {-1, 0, 1} f[ex_, sten_] := Sum[Map[# + tp &, ex, {2}] /. tp -> sten[[i]], {i, 1, Length[sten]}] Then, ...
Accepted

### Replacing a trigonometric value

See Why doesn't Mathematica know the exact value of some trivial trigonometric functions? FullSimplify[FunctionExpand[Tan[42 \[Degree]]]] ...

### Replacing a trigonometric value

expression /. Tan[42 Degree] -> (-Sqrt[6 - 2 Sqrt] + Sqrt[6 (5 + Sqrt)])/(2 Sqrt[ 7 - Sqrt + Sqrt[30 - 6 Sqrt]])

### Constructing a RootSum object changes existing internal syntax

Another workaround is not to put the single Function variable in a list. ...
Accepted

### Timing Discontinuity with Replace[] Function

There are a couple things going on here, from what I can tell. First, my guess is that at some level, somehow, it has something to do with the fact that we suddenly need more bits to represent all the ...

### Replacing large numbers

Using Condition: l /. x_Integer /; x > 10^6 -> 0 (*{{1, 2, 3}, {4, 0, 5}}*) Or in the same way: ...

### Replacing large numbers

You could use 3-arg Clip: Clip[l, {-Infinity, 10^10}, {0, 0}] {{1, 2, 3}, {4, 0, 5}} where I used ...

### Replacing large numbers

l = {{1, 2, 3}, {4, 10^(16), 5}} Define a high, low threshold as well as a substitute. thlow = 2; thhi = 3; subst = 11; Find ...

### Replacing large numbers

I'm assuming you want something generalizable. Let's say your threshold is 10^10, then something like this: Map[If[# > 10^10, 0, #] &, l, {2}] You could ...
Accepted

### Constructing a RootSum object changes existing internal syntax

The bug does not exist for Slot, just for Function with named parameters. (A dummy variable is substituted for ...
1 vote

### How to use a rule such that it substitutes the value x and derivatives of x in the expression?

Rather than answering directly, let me try to you give some background info that will hopefully help you understand this yourself. Suppose you enter an expression such as ...

### How to use a rule such that it substitutes the value x and derivatives of x in the expression?

The short form of your functions since you don't give the whole expression F = 2*m + H[t, r] + D[H[t, r], r, r] + D[H[t, r], t, r] set the rule to include ...
Accepted

### How to use a rule such that it substitutes the value x and derivatives of x in the expression?

To obtain H -> Function[{t, r}, G[t, r]]form, use the following: ...

### Simple, fast re-defining a part of 2D list

Another option is to use ReplacePart ...

...
Accepted

### Can substitution rules be used in function definitions?

It's not a problem with using rules in the def; it's a problem of whether x literally appears in the rhs or not. When applying a definition where the pattern ...

### MatchQ returns False for a match for e1 ** e2 while matching both e1 and e2

Your seem to want your last expression interpreted as (2 e1) ** (-2 e2), i.e the NonCommutativeMultiply between (2 e1) and ...