Questions tagged [replacement]
The replacement tag has no usage guidance.
1,429
questions
3
votes
1
answer
38
views
Terms of expressions with non-commutative multiplication that meet the given criteria
There is the following expression:
expr=a^3**x**Transpose[x]**y+x+y**Transpose[y]**x**a^3+x**Transpose[y]
It is necessary to apply the ...
7
votes
6
answers
373
views
'Mapping' the values of a list to variable
Suppose I have the variable expr1 = a[n] + b[n], and the list stencil={-1,0,1}. I want to make a function ...
0
votes
0
answers
39
views
Replace Derivative[ i ][ f ][ t ] with f[ i, t]
Assume the PadeApproximant is carried over f[t0] * g[t0] with the order {1, 1}, that is
<...
4
votes
2
answers
183
views
Tropical Operation Conversions: Multiple Operations
I apologize if my syntax is bad. I looked around, but didn't see anything on this in the stack exchange.
I would like to be able to transform a classical real-valued polynomial to a tropical ...
4
votes
1
answer
68
views
Replacement, PatternTest, Module related Question
Let's see how MMA handles following type of expression :
Replace[L, {pattTest1->rhs1, pattTest2->rhs2, pattTest3->rhs3}, {1}]
Specific example :
...
3
votes
1
answer
78
views
Classifying elements, by the value of a fixed function, using Replace
Let L be a list of several lists. And the length of each list is less than 1000.
You can create L by
...
3
votes
1
answer
48
views
ReplaceAll not working with change of sign
I obtain the following results
...
0
votes
1
answer
32
views
How to replace derivatives of a function with symbolic symbols and numbers with a replacement rule? (I.e. U'' maps to u2)
Suppose I have the expression:
expr = U''[x] + U'[x]
I would like to be able to write an abstract replacement rule so that I can transform the above expression to:
...
2
votes
1
answer
124
views
ReplaceAll with Powers
If I run the following code:
a^2/b^2 /. {a/b -> c}
I'm getting output:
a^2/b^2
How can I obtain ...
7
votes
5
answers
389
views
Smart way to remove rules from lists, leaving just values, specifically from FindMinimum output
I would like to know if there is a direct way to remove the rules from a list of rules.
I know that, simply, this can be done with:
...
7
votes
9
answers
777
views
What is an easy way to transform an equality into a replacement rule?
I found the necessity for the following procedure and was surprised I couldn't find a built-in function to do the following. I include my solution in case someone needs the same functionality, but if ...
7
votes
3
answers
252
views
Removed all undefined from a list of rules
My output from NSolve is a list of rules, most of these are undefined, I want to remove those rules.
More specifically I have a list
...
0
votes
1
answer
62
views
How to use "Replace" in matrix? [closed]
I would like to change the form of matrix output, for example:
A = {{1, 0}, {0, 0}};
B = {{0, 0}, {1, 0}};
B.A
This will give me a matrix that is the same as the ...
5
votes
4
answers
201
views
Replace list of list according to second list
Given
p = {{2, 0}, {3, 0}, {4, 0}, {5, 0}, {8, 0}, {11, 0}}
I want to replace parts according to a second list t1 if the first ...
3
votes
2
answers
124
views
Replacing an arbitrary function of a variable [closed]
If I do something like
1/Sqrt[x] /. {Sqrt[x] -> a}
it does not lead to an expected result, but can be fixed with
...
8
votes
3
answers
486
views
Replace 'n'-th occurence with number 'n'
How can I replace n-th occurence with number n for string/for list?
For string :
...
1
vote
1
answer
66
views
The replacement operator -> and :> and pattern
I'm confused by the difference between two replacement operators -> and :>, and their relation with the dummy variable (...
6
votes
3
answers
399
views
How can I change the expression x1 to x[1] in a simple way?
I have one expression,
exp0=x1+x9/8+ x4 x5
I want to get
exp1=x[1]+x[9]/8+x[4] x[5]
Is there a very simple way to do that?
3
votes
2
answers
179
views
How does NumberQ work [closed]
I want Log[2 x / Pi] to be expressed as Log[2/Pi] + Log[x]
so I make this replacement
...
1
vote
2
answers
94
views
Replacement rule for functions of two variables
In Mathematica when I use the substitutions rule (/.) If I have two variables {NN,H} each variables has 5 values and i want to substitute about the first variable ...
1
vote
0
answers
56
views
How to make a replacement rule matching exponents including 0 and 1
==============Edit for solution(s):
For anybody who does not need to worry about the structure of any coefficents and has non-negative powers this solution from @kirma works very well:
...
2
votes
1
answer
43
views
Substituting a function into a symbolic derivative term giving summations
Suppose I have terms which are symbolic derivatives of an undefined function:
f'[x]
(* Derivative[1][f][x] *)
If I later find out that this function can be ...
3
votes
2
answers
82
views
Why does the function replacement not work here?
why does the function replacement not work here?
b[1, x_] := x^2;
a'[x] /. a -> Function[x, b[1, x]]
gives $b^{(0,1)}(1,x)$ without evaluating further.
I would ...
0
votes
0
answers
69
views
why two different mathematica files with the same ODEs substituted with the same values give me different output?
I have a big struggle with numerical solution of a set of 3 ODE equations in one .nb file. This is completely wrong when I when use NDSolve[] command for them with previous substitution of certain ...
1
vote
1
answer
101
views
Solving for linear combination of variables
I have a set of constraints on nine variables,
...
0
votes
0
answers
34
views
Define a new rule to take precedence over the others in a symbol's `Downvalues` list [duplicate]
I have a symbol that has a very large list of Downvalues. One of the rules in this list should be applied before the others because it simplifies many expressions, ...
1
vote
1
answer
63
views
ReplaceAll command using list elements
I'm trying to define a function that replaces certain expressions that appear when calculating scattering amplitudes (not important). Basically, I have a function ...
9
votes
3
answers
426
views
Evaluating expressions by applying corresponding rules stored in another list
I have a list of expressions:
{x,x^2,x^3}
and a list of rules
{x->1,x->2,x->3}
How can I get ...
4
votes
1
answer
74
views
Substitute function back into solution
I have a expression
G[x] := (1-x^2)(1+A*x)(1-a*x)
where $(a,A) \in \mathbb{R} $.
Now this heavily simplifies some other expression. But these expression are no ...
1
vote
0
answers
29
views
Solve the current equation with respect to one of the coefficients and substitute it into each equation of the system
Good day to all!
In this question about recurrence relations, I had a simple case when the k + 1th variable is represented in terms of ...
2
votes
2
answers
56
views
Substitude similar symbols
In the examplary list
...
2
votes
2
answers
134
views
Replacing a column in a matrix by its Log [closed]
I have a nx3 matrix (called Plottable) filled with non-negative reals and I am trying to change the third column to its logarithm, but the /. operator doesn't change anything in the matrix. If I try ...
0
votes
1
answer
59
views
Double Sum, taking a constant out of the first sum gives a different result
I have a code with the following double sum:
Sum[Sum[(-1-k+f[k]) (-l+n+f[l]), {l,k+1,n}], {k,1,n}] /. f[r_] -> If[r == 1, n, 0]
With that, I get:
I wanted to ...
0
votes
0
answers
33
views
Wait replacement before NIntegrate
To pose my question more concretely, let me consider the minimal example
NIntegrate[1, {u, 0, a}] /. a -> 0.241
which gives as output:
...
6
votes
1
answer
178
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.
...
2
votes
3
answers
167
views
Replace something to an expression
After some calculations, I get some long expressions. I want to change some variables to get simple looks.
For a just small example:
But it doesn't work.
I convert the expression to ...
1
vote
2
answers
82
views
Change a value within a list from a string to number
I have a table with 10 columns. The last column contains a string; e.g.,
"center", "passageway 1", up to "passageway 8".
I want to change the last column so that the ...
1
vote
1
answer
29
views
NCReplaceRepeated destroys noncommutativity; is this a bug?
I am pretty new to patterns in Mathematica. Here is the example I want to consider:
...
5
votes
1
answer
51
views
Replacement of Association value does not evaluate
Cos[a - b] /. {a -> 0, b -> 0}
gives 1
However,
<|1 -> Cos[a - b]|> /. {a -> 0, b -> 0}
gives
...
3
votes
1
answer
73
views
Is there any particularity of Sum/Product in replacement
Here is an simple replacement:
Log[x[k]] /. Log[a_] -> a*xbar
I get the answer in my mind:
xbar x[k]
Similarly, I use ...
0
votes
0
answers
49
views
Algebraic substitutions in order
I have some symbols xp[m,n] that satisfy recursion relations, rule1, rule2, rule3. I would like to use the relations to reduce ...
4
votes
2
answers
233
views
What is the use of a list of replacement rules, when there are no curly braces around each one?
I've noticed the following in the Mathematica documentation for ReplaceAll:
...
4
votes
2
answers
126
views
Replace part of a List using 'ReplacePart'
I have two lists, List0 and List1 that have specific structures. I want to replace the second number in each pair of numbers in List0 with subsequent numbers from a flattened version of List1. This ...
1
vote
2
answers
122
views
Replacement with equivalent local variable and global variables give apparently different results using the same NDSolve output
I am solving a system ODEs which Mathematica quickly gives me a result varsol and dvarsol. Up to this point, everything is good.
...
1
vote
1
answer
35
views
Rules for internal functions
I'm at my string rewrite systems again. I always implemented these as rules on function arguments. For example, assume a rule is you can drop all arguments 0:
...
0
votes
1
answer
43
views
weird behavior in pattern-matching and condition
I'm confused by the following three different results involving pattern matching and condition.
...
4
votes
1
answer
96
views
How to use ReplaceAll to create Association from List
I want to create a List of Associations from data in a two-dimensional List by using ...
1
vote
0
answers
31
views
Is it possible to add "Synonyms and Antonyms" to the rightclick menu like office word and do the replacement in place?
When we write some note or comments in the notebook, Mathematica provides an spell check and we can select the right word to make it right. Mathematica 12.0 also provides a function to find the ...
5
votes
1
answer
134
views
How can I remove First[{}] from the output list of a function?
Consider:
listOfKeys = {"Ambientalismo", "Anoressia"};
list2 = First /@ (WikidataSearch /@ listOfKeys)
I've tried
...
8
votes
1
answer
420
views
Rule rewriting behavior
This is kind of meta-programming attempt. Below are two snippets:
Snippet 1:
...