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

learn more… | top users | synonyms (4)

2
votes
2answers
98 views

Converting a date to a calendar quarter

I have a list that includes dates. I need to convert each date to be the last day of the quarter that it's in. So for example I want {2013,7,1,0,0,0} to become {2013,9,30,0,0,0}. Actually I don't ...
0
votes
1answer
88 views

Want to use column names as indices, but without quotes

The following works: ...
1
vote
1answer
45 views

Different ordering for KroneckerDelta?

I have an expression like this: Assuming[m [\Element] Integers && n [\Element] Integers, 1/2 I J n (4-m n+n^2) KroneckerDelta[m,-n]]//FullSimplify Now, ...
7
votes
1answer
173 views

What is the principle behind Dispatch?

I want to know what Dispatch actually does to rule the list. Why is it so fast? The documentation says Dispatch generates a dispatch table which uses hash ...
0
votes
1answer
100 views

replace is not happening for specific vector valued expression

Given x[t_] := {Subscript[x, 1][t], Subscript[x, 2][t]} following replace works fine x[t] /. x[t] -> 0 0 but following ...
1
vote
2answers
64 views

How do I avoid vector variables being treated as scalars in the course of replacements?

I often work with a mixture of symbolic and concrete values as I develop teaching materials. I introduce variables symbolically and then need to instantiate them to specific values while continuing ...
1
vote
2answers
85 views

How to define a rule to simplify the notation for derivatives of chain rule?

Suppose that $u(x,y)$ is a function, and $x=r \cos t$, $y= r \sin t$, then we can define a new function $v(r,t):=u(x,y)$ with $x,y$ replaced by the above equations. It is quite easy to compute $v$'s ...
0
votes
0answers
43 views

is there a way to speed up rule replace? [duplicate]

I am currently doing calculation with 7 parameters, each parameter set corresponding to a value. And I store the data in the format as a list of rule, like following ...
5
votes
4answers
224 views

How to split a list with respect to its nested sublists?

I have a problem with the following task: having some nested list list = {{k6},{k1,k3,k5},{k7}} I would like to replace all sublists by their permutations and ...
0
votes
2answers
128 views

Replace doesn't replace the denominator [duplicate]

I have the following expression in Mathematica -((E^(2 - 2 Sqrt[(x[1] - x[2])^2]) (x[1] - x[2]))/Sqrt[(x[1] - x[2])^2]) I want to replace anything of the ...
2
votes
1answer
122 views

Derivation after substitution not working

I have a code that will output an expression in form of a functions like this ...
3
votes
3answers
71 views

Operations on expressions within Hold [duplicate]

I want to convert {Hold[1 + 2], Hold[3 + 4], Hold[5*6]} into Hold[{1 + 2, 3 + 4, 5*6}]. I have tried ...
0
votes
1answer
126 views

How to return the rhs of a transformation rule from within Compile[]

I have defined the following function: ...
0
votes
1answer
85 views

Function generating a rule with a Patterns: e.g. toRule[ lhs, rhs] into lhs[x_] -> rhs [duplicate]

I want to create a rule as a function of z from a left and right hand side. My (non-working) code and usage is: ...
5
votes
0answers
185 views

Is everything in Mathematica ultimately stored as a rule?

My current understanding about Mathematica is that everything, at the lowest level, ends up as replacement rules. First question: is this true? Second question: does Mathematica "gloss over" these ...
4
votes
2answers
114 views

BezierCurve in EdgeShapeFunction fails when used on multiedges graph

I would like to create a network graph with curved edges. To do this, I wrote this function: ...
2
votes
2answers
130 views

How to plot complex values given by Solve

Update Solve[N[Table[BernoulliB[n, z], {n, 10, 10}] == 0]] ...
4
votes
3answers
140 views

Simplifying expression with patterns (Replace)

Q1: I need to simplify some algebraic expression, according to particular pattern, namely: \begin{equation*} x^m = \left\{ \begin{array}{ll} 1 & \text{if } m \text{ is even} \\ x & \text{if ...
4
votes
4answers
140 views

Rearrange graph

I have to rearrange graph described by j = {1 -> 2, 2 -> 3, 3 -> 1}; appling some function to all vertices on the right so rearrange[j] output should ...
1
vote
1answer
76 views

An equivalent in Mathematica [duplicate]

Let's say I have a $n$x$m$ matrix $M$ in Matlab and I want to substitute the elements of $M$ that exceed $15$ for $-1$. In Matlab I just write M(M>15)=-1 and ...
11
votes
4answers
290 views

How to replace every possible $A+B$ and $AB$ in expansion of $(A+B)^{10}-A^{10}-B^{10}$ with $x$ and $y$, respectively?

I would like to replace every possible $A+B$ and $AB$ in expansion of $(A+B)^{10}-A^{10}-B^{10}$ with $x$ and $y$, respectively. How to do it with the simplest code in Mathematica? For example, ...
0
votes
1answer
68 views

Manipulate that remembers its own input code and can show it by request

This question is a further question to my previous one. The solution for that question works well as long as the original input Manipulate code is still provided in ...
1
vote
2answers
168 views

How to replace subscript symbols

I have an expression with subscripted variables. I would like to replace all those terms with other symbols. For example, $P_1 + P_2^3 \rightarrow P1 + P2^3$ I used the following code but it doesn't ...
3
votes
1answer
144 views

Is there a way to simplify this replacement rule

I have a rather big expression which contains many sums of form q x + w y. I know that y is much smaller than ...
0
votes
1answer
91 views

Problem with List Dimension Outer Map [duplicate]

I am currently handling a big list which has the following dimension: {6, 3, 4, 2, 2, 1, 8} where the last number 8 represent a ...
3
votes
1answer
93 views

obtaining real roots of negative numbers in a long expression [duplicate]

I have a complicated symbolic expression which contains many terms like $(a/(a-2))^{1/m}$, where $a/(a-2)$ could be positive or negative after replacement. I only need the real root after ...
3
votes
3answers
334 views

StreamPlot using NDSolve gives error messages

StreamPlot[{x[0], x'[0]} /. NDSolve[{x''[t] == 1, x'[0] == v0, x[0] == x0}, {x, x'}, {t, 0, 1}], {x0, -2, 2}, {v0, -2, 2}] The above code gives me the errors ...
1
vote
2answers
235 views

How to debug error triggered by replacement rule?

The second line below produces the errors shown: ...
0
votes
1answer
133 views

Checking differential equation solution

I have this differential equation: eq=D[ψ[r],r]+A*ψ[r]-(B/(A*r))ψ[r]==0; And DSolve sucessfully solves it: ...
2
votes
2answers
158 views

Applying rules with functions to expressions with derivatives

I have a function that I want to see applied, potentially within a derivative. The use of delayed vs. non-delayed rules seems irrelevant. See the following: ...
2
votes
3answers
145 views

How to manipulate log arguments?

A common problem I have with Mathematica is needing to manipulate the arguments of logarithms. Typically, I need to take ratios of the log arguments Mathematica gives me by default. That's to say ...
1
vote
3answers
112 views

Replace inside a Held expression separate context

How do I replace content inside a Held expression without local values coming through? For example if you run the following code you get g[2] instead of ...
4
votes
3answers
139 views

Appending to sublists using “anchor” values

Say I have a set of lists that look like this: ...
3
votes
2answers
171 views

Can I ask Mathematica to replace the arguments of my functions with a replacement rule?

I have an equation that I evaluate at some point (let's say $x=1$) that have terms of the form f[1,y] D[g[1,y],{y,2}] Is there an easy way to replace [1,y] by ...
0
votes
2answers
166 views

Writing intelligent replacement rules for symbols

I am learning about quaternions right now, and I wanted to play around with some concepts I am learning. e.g. take rotation of a point about an axis with specified angle. ...
4
votes
1answer
195 views

How to speed up calculations with large number of replacement rules?

In my program I have an expression which looks like: ...
2
votes
1answer
151 views

Add Pattern to List Removing Duplicates

Lets say I have a list of patterns ...
1
vote
0answers
44 views

Best way to power series expand in multiple variables? [duplicate]

A power series expansion of a multivariate function can be performed with the Series command, which performs each expansion consecutively. The results can be a bit ...
0
votes
1answer
76 views

Scope of expression in a user-defined function

I have the following code: fbasic = A + R + Z*Z *Z*Z; f[A_, Z_, R_] := fbasic + R; f[0, 2, 3] The answer I am getting is ...
1
vote
2answers
73 views

Changing all link destinations in a notebook

I have a bunch of cells containing text and hyperlinks. i.e. of the form: ...
10
votes
3answers
454 views

How to properly project a Graphics object consisting of line primitives

My problem starts from attempts at depicting overlapping lines of different thickness, i.e. ...
0
votes
1answer
210 views

Problem with determinant calculation [closed]

I have a 12x12 matrix (2D list), called M, which depends on some variables. Usually I set all of the expect of one (call it x). ...
2
votes
1answer
86 views

Replace inverse function

I'm solving an expression like so: Solve[u[x] == u[a] + u[b], x] Mathematica returns {{x->(u^(-1))[u[a]+u[b]]}} If I ...
1
vote
1answer
124 views

Simple rule appears not to work

I have the following simple code ...
3
votes
1answer
107 views

How can I avoid this ReplaceAll trap? [duplicate]

I am having some difficulties with the ReplaceAll function. When I write: {1, 2, 3, 4, 5} /. x_?OddQ -> x^2 I expect: ...
2
votes
1answer
131 views

Strange behavior when replacing variables by numerical values [duplicate]

I have a rather complicated function with parameters {a, b, c, d, e, f, k}, and I'd like to know its behavior as a function of k alone given other parameters, so I try the following code: ...
1
vote
0answers
110 views

Variable scope in nested NMaximize, NMaxValue

I'm trying to use NMaxValue inside other statements (FindRoot and NMinimize). Those statements should bind variable names, but I'm getting weird warnings which seem to indicate that the variables ...
6
votes
5answers
203 views

Lowering the degree of an polynomial with an assumption that the polynomial has a factor x^2+ax+b

Let's assume $ x^{10}+x^5+1 $ has a factor $x^2+ax+b$ Then, If $x^2=-ax-b$, $ x^{10}+x^5+1 =0$. If we successively apply $x^2=-ax-b$ to $ x^{10}+x^5+1 $, we can make $ x^{10}+x^5+1 $ to degree 1, ...
1
vote
1answer
202 views

Equating and solving equations that have been generated using table[]

I am in the process of trying to use Mathematica to find the coefficients of transmission and reflection for the wavefunction of a beam of particles tunnelling across any number of identical potential ...
2
votes
0answers
103 views

Generalization of a rule to N arguments

I am trying to apply a series expansion on a function x[t1,t2,...tn], with an expansion parameter a. For ...