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

learn more… | top users | synonyms (4)

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 ...
1
vote
2answers
159 views

Using patterns in ReplaceAll to extract elements from tuples at arbitrary depths

Please consider the following: I need to extract from MyList all last parts of each 3-tuple. ...
1
vote
2answers
64 views

Replacing a specific pattern of values at level 2 in a list

I've a list of lists, tl = {{True, False, m12}, {False, m22, m33}, {m32, False, True}} and each nested list has the same length, What is the proper way to ...
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 ...
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: ...
1
vote
3answers
87 views

How can you form a variable from a function and its arguments?

Is there a way to make the general replacement foo[x,y,z]->fooxyz so that I can treat the x_i as variables so that I will obtain foofgh from the following: ...
1
vote
3answers
172 views

Help me to find a way to do this repetitive stuff

I'm trying to do this: ...
1
vote
2answers
325 views

Generating a list of rules [closed]

This is my first time asking a question on this forum. I would like to generate a list with a range of numbers and use this list for a function to read from. Ok, now for the good part, it would look ...
1
vote
4answers
91 views

Replacing more than one element from a Sublist

The following expression allows me to extract the value of x and y: ...
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 ...
1
vote
1answer
99 views

Matrix/tensor addition behaving funny under replacement?

I have two matrices I want to add, and one of the matrices is a tensor product of two vectors. I've used a SetDelayed to define the summed matrix, because I want to evaluate it for different values of ...
1
vote
2answers
86 views

How to “reversely” replace definitions?

I have the following problem at hand. 1.) I have a list of definitions like ...
1
vote
2answers
72 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
2answers
235 views

How to debug error triggered by replacement rule?

The second line below produces the errors shown: ...
1
vote
2answers
96 views

Looking for an elegant way to solve a (system of) ODEs/functional equations with undetermined coefficients

I want to solve an ODE using undetermined coefficients/guess-and-verify and am looking for an elegant way to use this technique. I am running into a few ugly warts. Here is a basic implementation for ...
1
vote
3answers
146 views

Conditional Check on Matrix

Suppose I have the following matrix (i,j): ...
1
vote
2answers
89 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 ...
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
1answer
201 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 ...
1
vote
1answer
1k views

Converting polar coordinate expression to cartesian coordinates

An intermediate step in my analysis requires me to work in polar coordinates, but I would like to convert the results back into cartesian coordinates. The conversion is very simple but tedious for ...
1
vote
1answer
34 views

Automatic substitution of fractions

I have several equations with many variables, and here and there I would like to do a variable substitution. For example, in the equation: a (b + 42 c / d) I ...
1
vote
1answer
76 views

Nest Replace Function with different rules

I have a table of data that I want to filter. Any value of zero in the table means that value was not calculated, so it should get populated with the tag "NC". Next the table is filtered for all ...
1
vote
1answer
107 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 ...
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, ...
1
vote
1answer
141 views

Improving the plotting time of a very complicated expression

The quatity $R$ is defined by a complicated expression in terms of $a_1,a_2,\ldots,a_n$. Now each $a_i$ is a function of $x$, $a_i(x)$. I would like to know what is the most efficient way to ...
1
vote
3answers
115 views

Auto simplifications of power products

Mathematica automatically simplifies Exp[a]Exp[b] to Exp[a+b]. The problem is now that I can't do this ...
1
vote
1answer
67 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: ...
1
vote
1answer
45 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. ...
1
vote
1answer
55 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
254 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
45 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 ...
1
vote
2answers
118 views

Why does using ReplaceAll twice produce a different result?

Why does this: Solve[a x^4 + b x^3 + c x^2 + d x + e == 0, x] /. {2 c^3 - 9 b c d + 27 a d^2 + 27 b^2 e - 72 a c e -> F} produce a different result from ...
1
vote
1answer
259 views

Arbitrary depth patterns/rules

Temporary message: I am now really confused. I am not sure how using Power and Unevaluated together works in the examples below. While answering this question, I stumbled upon the following. We ...
1
vote
1answer
99 views

given n lists, get list of applications of function to n-tuples

Is there a built in function or an easy rule to do the following transformation? H[{A[0], A[1], ...},{B[0], B[1], ...},...] into ...
1
vote
1answer
120 views

Match and replace subexpression

I would like to replace the expresion $(n1-1)$ to $z1$ in following: In[1] := 2*n1*p[n1-1,n2] Out[1] := 2*(z1+1)*p[z1,n2] I have tried ...
1
vote
1answer
150 views

Efficient way to give symbolic elements symmetry

I have a symbolic expression that represents a set of operators. These operators have quite a bit of symmetry to simplify expressions: ...
1
vote
0answers
38 views

How can I use the Rules returned by FindFit? [closed]

When I evlauate data = RandomReal[10, {5, 10, 2}]; fit[i_] := FindFit[data[[i]], a Sin[x] + b, {a, b}, x] fit[1] I get something like: ...
1
vote
0answers
36 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 ...
1
vote
2answers
108 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?
1
vote
0answers
60 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 ...
1
vote
0answers
59 views

Object depth different in replacement rule [closed]

I access the first part of an expression with head foo without a problem: foo[arg][[1]] arg Then when I try to use this ...
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 ...
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 ...
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 ...
1
vote
0answers
60 views

Abridging Lists of Equations within NDSolve, Manipulate [duplicate]

I have a pretty little NDSolve function that I've finally decked out with manipulatable (by sliders) coefficients, which changes the graph in real time. However, I ...
1
vote
0answers
43 views

plot[] with subsititution rule [duplicate]

I encounter this problem in Mathematica 9.0.1, I'm not sure if it ever happens in other version. Plot[{x, x + 1}, {x, 0, 10}, PlotStyle -> {Red, Green}] This ...
0
votes
2answers
72 views

Replace expression using a tuple

Given an expression in x, y, z (for example), and a list with three elements, like ...
0
votes
2answers
105 views

Why does Mathematica not replace the derivative of $theta$1'[t]?

I want to know the velocity of point $p$, given that I know the coordinate. $p_x=L_1\cos(\theta1)+L_2\cos(\theta1+\theta2)$ I calculate $\frac{dp_x}{dt}$ to achieve the velocity of point $p$ about ...
0
votes
2answers
113 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. ...
0
votes
2answers
78 views

Extract a List of Co-ordinates from a List of Complex Solutions

Let's say I have this list of solutions from a previous computation: ...