Questions about Mathematica's rule-based replacement functionality, including functions such as Rule (->), Replace, ReplaceAll (/.) and ReplaceRepeated (//.).

learn more… | top users | synonyms (4)

0
votes
0answers
74 views

Calculating the Lyapunov Exponent/Spectrum for the Duffing Oscillator

Some fellow students and I are trying to calculate and plot the Lyapunov spectrum for the Duffing oscillator (currently a test approach). Each of us has Mathematica knowledge based purely on past ...
0
votes
2answers
92 views

How to partition three years of data into daily samples

I'm trying to find mean of temperature data list. The temperature data list has 3 hours steps which means I have 365*8=2920 temperature measurements per year. My data are temperatures of 13 years. ...
2
votes
1answer
61 views

Using Total on a list supplied by a rule

I'm confused as to why Total complains about a nonatomic expression here: ...
1
vote
1answer
46 views

How can I get the functionality of a command ReplaceAllList?

I'm trying to use ReplaceList to match subexpressions. I expected the command: ReplaceList[{p, {p, p}}, {x_, y_} -> x y] to output two results, equivalent to: ...
0
votes
1answer
43 views

Replacing powers of $n$-th partial sums in the output of a function with $S[i]$ for $i = 1,\ldots,n$

I've written some simple code that, for various $N \geq 1$ and $k = 1,\ldots,N+1$ computes the $n$-th derivative of $\log S_N$ where $S_N(z) = \sum_{k=0}^N \frac{1}{k!}z^k$ as follows: ...
2
votes
1answer
42 views

Ordering for Pattern matching in Subscripts

I have some transformation rules acting on subscripted variables. When I match the a product the order matters. ...
0
votes
1answer
82 views

Replacement rules in combination with pure functions to make a change of variables

I have defined my function in this way w = f[r,Θ] ; After some calculations i obtained my results with respect to the previous function. For instance: ...
3
votes
1answer
146 views
1
vote
1answer
94 views

Matrix substitution

I'm newbie in Mathematica and would like to ask one simple question. Let's say I have matrix with some elements == -1 ...
2
votes
1answer
57 views

Applying rules to rewrite expressions that contain patterns

I'm trying to write a rule that can rewrite a pattern that exists in another expression. For some reason, this is proving to be more challenging than I expected ... most likely because I'm not totally ...
1
vote
0answers
30 views

How to apply an rule to factors matching a certain form

Suppose we have many expressions involving irrational ArcTan expressions (such as ArcTan[Sqrt[3],5]) along with other irrational factors (such as ...
0
votes
1answer
60 views

Replace one order of derivative inside higher one

How could I replace for example: Derivative[2][f][x] by Derivative[1][g][x] where ...
0
votes
2answers
76 views

Replace matrix with conditions

I want to replace the values of 1. in slot under the condition that the year and month in basevalue and ...
0
votes
1answer
42 views

Solve equation with two different sets of replacement rules

I want to solve eqn for c0. I want to do it with both replacement rules. I realize I could just use solve twice, once for subsCoke, and once for subsPepsi. I'm trying to do it in just one Sovle to ...
1
vote
1answer
38 views

Commutative algebra by generators and quadratic relations

My apologies if this has been asked before. Please also be gentle, as this is my first question here. I am trying to define a commutative algebra by generators and relations in the following way. ...
10
votes
3answers
200 views

Replacing parts of a held expression with held parts of another expression

I'm applying the Trott-Strzebonski technique in order to replace inside a held expression. ...
0
votes
0answers
28 views

Block, With, Module, can anyone help me understand the distinction? [duplicate]

I've been working heavily with Block[] for months in my research so I've read the documentation for the seemingly similar commands With[], Block[], and Module[]. Personally, I've had by far the ...
0
votes
1answer
54 views
1
vote
3answers
111 views

Conditional Check on Matrix

Suppose I have the following matrix (i,j): ...
0
votes
0answers
64 views

Back Linear Substitution

I have an equation set Ax=b and A(n*m),n<m . To lower down the dimension, I express some vars by other vars, which gives ...
0
votes
0answers
18 views

Manipulating named patterns inside replacement rules [duplicate]

When I evaluate the following expression, {a -> "value1", b -> "value22"} /. {Rule[x_, y_] -> Rule[x, y]} I get ...
3
votes
0answers
60 views

Why doesn't ReplaceAll work on Image? [duplicate]

ReplaceAll seems not to reach inside Image, and I don't see why it shouldn't. Here is an example. Create a black and white image ...
1
vote
2answers
61 views

Replace a column in table with a list of numbers?

I have a Table of values e.g. {{x,y,z},{x,y,z},{x,y,z}…} How do I replace the the "z" column with a List of values?
4
votes
1answer
136 views

replace items in a list with items in a another list

Suppose I have a list A={x1,x2,x3}, a list B={3,4,5}, and a function f[x]=x1+x2+x3. Is there ...
0
votes
0answers
69 views

Patterns and replacements [on hold]

I basically need to read off informations from an expression in order to apply some recursion relations. The terms I encounter have a form like $f(k) = (1+ k_{\alpha}^{n1} k_\beta^{m1} ...
2
votes
2answers
100 views

Generating an editable table that can be used as input

Say I have a number $n_{max}$. I want a command to generate a table like 1 1 2 2 3 3 4 4 ... nmax nmax where the second column is editable, and this table can be ...
1
vote
2answers
80 views

How to “reversely” replace definitions?

I have the following problem at hand. 1.) I have a list of definitions like ...
0
votes
2answers
88 views

Handling output that was returned unevaluated from a function

When evaluating functions, including those described in this post, how do Mathematica users handle values returned from a function that are unevaluated? For example (based on 1): ...
1
vote
1answer
27 views

Table doesn't replace inside conditionals (If, Which) [duplicate]

This: Table[If[cond, y], {y, 1, 3}] outputs this: {If[cond, y], If[cond, y], If[cond, y]} The ...
6
votes
3answers
269 views

How to make all numbers equal to one in a Series?

I have many outputs of one-dimensional Series expansions for which I am only interested in the general tending with the variable. For example, I would like to be able to transform something like ...
5
votes
2answers
154 views

How to “ReplaceAll” using a set of conditional expressions instead of a list of rules [closed]

Suppose that I have two linear functions f[x_] := f0 + f1 x g[x_] := g0 + g1 x and a (possibly rather complicated) set of conditional expressions, obtained ...
1
vote
2answers
63 views

How do I use a passed-in symbol as a tag to define UpValues?

ClearAll@foo; foo[tag_] := ( tag /: tag[i_] := tag[[i]] ); a = {7, 8, 9}; foo[a]; a[2] I wanted the above to output 8, ...
1
vote
1answer
52 views

How do I extend (prepend or append to) an existing TagSetDelayed rule? [duplicate]

I have a TagSetDelayed rule associated with, say, tag: ...
1
vote
1answer
124 views

How to properly substitute values into variables?

I have an array of functions in terms of a[0] through a[n] and I wish to replace the a[]'s with previously calculated values p[0] through p[n], as in below: ...
1
vote
1answer
42 views

How to substitue local variables into expression with free variables?

I'm wondering how to do the following: expr = L + R; foo[L_, R_] := expr; foo[1, 2] (* L + R *) and have it substitute the function variables ...
7
votes
3answers
139 views

Converting StringJoin to StringForm inside Hold

Let's say I have a piece of code: Hold[{code1, "asdad " <> ToString[testa] <> " adsd " <> ToString[testb], code2}] (*MWE ofc*) ...
1
vote
2answers
88 views

How to get a rule for, e.g., (x + y) to apply to (-x - y), etc.?

For example, the substitution (x + y) -> s fails here: In[1]:= (-x - y) /. (x + y) -> s Out[1]= -x - y Of course, I ...
3
votes
2answers
94 views

truncating terms in symbolic expression basing on their values

I need to simplify big symbolic solution of equations system by truncating terms that are orders of magnitude less then others in subexpressions like a + b. The solution is big fraction with sum of ...
3
votes
1answer
60 views

Have transformation rules to be explicitly set?

I think this problem is not the hardest one, but I can't hit on it. I want to NSolve an equation. For this equation I use a transformation rule "ampTimes". First I used it like this: ...
3
votes
1answer
83 views

Replace rule with function? Derivatives don't evaluate

Say I have an expression (call it expr) involving a function, f[x]. I'd like to be able to evaluate that for a particular choice of f[x] without setting that choice for the whole session. I thought to ...
3
votes
4answers
188 views

Replace symbols with values without evaluation

If I have assigned values to a, b and c: ...
3
votes
1answer
53 views

Replacing multiple instances of a symbol with different variables and assignments

I have an expression of the form: expr=x+y+n+Sin[n]+n^2 I would like to replace each of the variables n with a different ...
3
votes
1answer
83 views

some confusion about ReplaceRepeated

This is Right. NestWhile[Log, 100, # > 1 &] {100} //. {x_} /; x > 1 :> {Log[x]} 100. //. x_ /; x > 1 :> Log[x] This is wrong,why? ...
0
votes
1answer
74 views

How to convert the expression '{a->a0, b->b0}' to the expression 'a=a0; b=b0'? [duplicate]

How to convert the expression '{a->a0, b->b0}' to the expression 'a=a0; b=b0'? I think this is a common question and do not know if someone has asked it before. Any help or suggestion will be ...
1
vote
0answers
57 views

How to simplify expressions

I read several similar posts but I have not found a solution yet. However, I think that my problem should be quite easy. So here we are. Relations ...
0
votes
1answer
81 views

How to replace multiple variables at once

I would like to make a replacement "c1 C1 -> F1, c2 C2-> F2...." such that the expression like this "c1 C1 c2 C2 c3 C3 c4 C4" becomes "F1 F2 F3 F4". I used the standard replacement method: ...
0
votes
1answer
85 views

How to transform the polynomial in this way?

I have two functions f and g and a polynomial ...
0
votes
3answers
138 views

Replace all elements of a list

I have a set that looks like: s = {{1, 2, 3} -> 9, {4, 1, 9} -> 9, {3, 7, 3} -> 1}; Now, I want to replace each element of the set by the lhs of "...
0
votes
0answers
64 views

Alternate method of conjugation using replaceall

Mathematica really struggles to simplify complex conjugates of complicated expressions - even given assumptions for every symbol in the expression being real. Often times I've found that I can ...
2
votes
1answer
65 views

Convert Integer to Numeric with Replacement rules

I have a long list of triples, each looking something like {AGO, 1988, 2345.23}. Some of these, however, have an integer in the third spot, like this: ...