New answers tagged replacement
0
votes
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 ...
0
votes
Replacement of a variable only for a part of an expression
You just need ReplacePart
Where ReplacePart[Function/Expression , Location which part to replace]
...
2
votes
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?)
...
3
votes
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 &...
3
votes
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*)
{...
4
votes
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.
...
7
votes
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:
...
2
votes
How to replace anti diagonal elements of a matrix
With[
{mask =
Reverse[ReplaceAll[DiagonalMatrix[Function /@ Diagonal[m]], 0 -> Identity], 2]},
MapThread[Construct, {mask, m}, 2]]
5
votes
5
votes
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:
...
2
votes
'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, ...
6
votes
Accepted
Replacing a trigonometric value
See Why doesn't Mathematica know the exact value of some trivial trigonometric functions?
FullSimplify[FunctionExpand[Tan[42 \[Degree]]]]
...
2
votes
Replacing a trigonometric value
expression /.
Tan[42 Degree] -> (-Sqrt[6 - 2 Sqrt[5]] +
Sqrt[6 (5 + Sqrt[5])])/(2 Sqrt[
7 - Sqrt[5] + Sqrt[30 - 6 Sqrt[5]]])
6
votes
Constructing a RootSum object changes existing internal syntax
Another workaround is not to put the single Function variable in a list.
...
5
votes
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 ...
5
votes
Replacing large numbers
Using Condition:
l /. x_Integer /; x > 10^6 -> 0
(*{{1, 2, 3}, {4, 0, 5}}*)
Or in the same way:
...
15
votes
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 ...
2
votes
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 ...
2
votes
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 ...
6
votes
Accepted
Constructing a RootSum object changes existing internal syntax
The bug does not exist for Slot[1], 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 ...
2
votes
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 ...
5
votes
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:
...
13
votes
11
votes
6
votes
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 ...
3
votes
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 ...
0
votes
Why do two different Mathematica files with the same ODEs substituted with the same values give me different outputs?
The problem was that the numerical data values should be put right before the NDSolve command execution (not earlier)-then it can handle this really well. I dont know why it is such a difference for ...
3
votes
FindFit with Replace error
To get things to work I changed the following: (1) = to := in the definitions of k1eqn and <...
Top 50 recent answers are included
Related Tags
replacement × 1441list-manipulation × 235
pattern-matching × 196
rule × 164
simplifying-expressions × 81
functions × 69
matrix × 65
expression-manipulation × 63
evaluation × 57
string-manipulation × 55
equation-solving × 52
function-construction × 50
calculus-and-analysis × 45
symbolic × 40
differential-equations × 35
performance-tuning × 34
hold × 29
algebraic-manipulation × 27
table × 26
plotting × 24
associations × 23
conditional × 21
syntax × 20
polynomials × 18
scoping × 18