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
2answers
115 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
98 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
116 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
0answers
37 views

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

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
1answer
47 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
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 ...
1
vote
2answers
64 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
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 ...
1
vote
0answers
51 views

Object depth different in replacement rule

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
73 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
40 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
101 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
71 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
96 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
77 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: ...
0
votes
2answers
146 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. ...
0
votes
2answers
191 views

characteristic polynomial based on differential equation

I have this differential equation: $$\ddot{x}-\frac{1}{6} \dot{x} - \frac{1}{6}x = e^t$$ When I DSolve it looks like this: ...
0
votes
2answers
158 views

Converting a list of replacement rules into a list of real values [duplicate]

The following command outputs a list of replacement rules. ...
0
votes
1answer
121 views

Apply rule only if applicable? Check rule applicability? Custom unapplicable rule?

How to avoid recursion in the following example? ...
0
votes
1answer
77 views

What exactly happens when adding a Blank after a built-in function used in the rules of ReplaceAll?

Well, this question is just for curiosity, personally I never use ReplaceAll like this: ...
0
votes
1answer
84 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 ...
0
votes
1answer
123 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: ...
0
votes
1answer
115 views

Numerical rule evaluation -> {True, False} to deviation of target equation

I solve some equations numerically with FindRoot[] returning a quadruple {1,2,3,4}. Because the solver sometimes do not find any roots depending on parameterization of these equations I select only ...
0
votes
1answer
45 views

Append subscript to variable name [duplicate]

I'm importing equations from Word document and transforming them into input form. But subscripts look ugly. Is is possible to programmatically append subscript to variable name? e.g. ...
0
votes
2answers
77 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
2answers
90 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): ...
0
votes
1answer
82 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
3answers
140 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
2answers
107 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 ...
0
votes
1answer
66 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 ...
0
votes
2answers
72 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 ...
0
votes
1answer
241 views

Make Mathematica wait before replacing?

How can I force Mathematica to completely evaluate a subexpression before using a replacement rule? For example, consider the following definition (for the series of ...
0
votes
1answer
139 views

simplification rule with symmetry

What rule can you think of to replace the first line by the second? I have a bunch of expression like these, which I would like to simplify. All dependent cross terms must be written in the same ...
0
votes
1answer
84 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: ...
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 ...
0
votes
1answer
54 views
0
votes
1answer
75 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 ...
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
1answer
84 views

Want to use column names as indices, but without quotes

The following works: ...
0
votes
1answer
104 views

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

I have defined the following function: ...
0
votes
1answer
76 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: ...
0
votes
1answer
181 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). ...
0
votes
1answer
105 views

Problem with Replace rules [closed]

I am struggling with a Project Euler problem with Mathematica, what I want to do is to Replace a list like this {5,6,x,x,3} with the rule {x -> i} to {5,6,0,0,3}, {5,6,1,1,3}etc,and here is my code: ...
0
votes
1answer
235 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 ...
0
votes
1answer
113 views

How to change variable that has been defined in PDE?

I have a PDE function that contains a variable (named ka). I want to plot the result of my PDE in 1 plot using several different ka values. However, I'm not sure about how to write down this equation. ...
0
votes
2answers
123 views

How to use Solve rules as a function body?

Solve gives me an expression which I want to use as the body of a function. Rather than run Solve every time inside my function ...
0
votes
1answer
134 views

Extract a value from a list of InterpolatingFunction

By running the code n = 5; U[t_] := Table[Subscript[u, i][t], {i, 0, n}]; lines = NDSolve[{eqns, initc}, U[t], {t, 0, T}] I get the output ...
0
votes
1answer
710 views

Plot is not showing [closed]

I've used Wolfram Mathematica 8 Trial version for two days. Any pointers are appreciated. Thanks in advance! EDIT: There are supposed to be 4 plots, but only 3 are showing. Everything works except ...