Questions tagged [replacement]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
30 views

How to replace a function [duplicate]

I want to replace the function y[x] in the following expression with function y[x]=x^2 ...
0
votes
0answers
27 views

replacing a founded value in a function

Here is the sample F[r_] := r^2 + r^3 DerivI[r_] := D[F[r], r] A = FindRoot[DerivI[r], {r, 9}] B = F[r] /. r -> A I want to replace ...
1
vote
0answers
22 views

Simplify each coefficient of coefficientlist individually and automatically substitute any repeats

I have a 13x13 polynomial coefficient list that I create with: CoefficientList[Expand[myequation] /. Equal -> Subtract,{x,z}] I would now like to simplify ...
1
vote
1answer
40 views

How to deal with procedurally generated rules and patterns?

I'm trying to procedurally generate replacement rules of the following form ...
0
votes
0answers
58 views

Teach Mathematica analytical continuation of the gamma function

If I ask Mathematica to compute the gamma function for me Integrate[Exp[-s] s^(a - 1), {s, 0, Infinity}] It dutifully returns to me ...
1
vote
2answers
44 views

How to apply different rules to multiple appreances of the same variable?

For example, I have two lists. The first list listA = {x, x^2, x^3} has some elements involving the same variable x. The second ...
0
votes
1answer
52 views

Converting numbers and expressions

Trying to create a rule to convert negative numbers/expressions positive. So far: f[-x_]:> f[x] Trying to extend this rule to floats such as -1.0 and ...
2
votes
4answers
131 views

How to replace the string

How to replace the string k with 1*^3 and Hz with blank space, such that I could use ListLogLog[] ...
4
votes
1answer
56 views

Replace pattern with the number of matches so far

I want to replace a n-th pattern match in an expression with n. This is a very simple task, though it appears very hard to find an elegant implementation. For example, with input ...
1
vote
2answers
55 views

Assigning values to multiple variables from a list

I have a solution of the following form: $F(x)= \\ \qquad c+(x_0+x_1+x_2+\ldots +x_n)- \\ \qquad (x_0\,\log(x_0+\sqrt{x_0})+x_1\,\log(x_1+\sqrt{x_1})+x_2\,\log(x_2+\sqrt{x_2})+\ldots +x_n\,\log(x_n+\...
0
votes
1answer
31 views

Making substitution to an expressions with a list of numerical data [closed]

Suppose I have an expression similar to this: y=23.23*(h[x]^2)*(D[h[x],x])*(D[h[x],{x,3}])/(13.2+Cos[0.245x]) The actual expression is a lot more complicated, but ...
4
votes
4answers
196 views

How can I use the solutions of coupled nonlinear equations as functions of its parameters?

I have a set of coupled nonlinear equations. I want to plot all the possible solutions as functions of the parameter AA. I have tried this code but it does not work. ...
8
votes
2answers
309 views

StringReplace with multiple patterns

I am experiencing what seems to be a strange behaviour with StringReplace while trying to add an extra pattern to an existing list of patterns. The problem is to translate a string into Morse code, ...
1
vote
0answers
63 views

Find all pattern in expression

Consider this problem: I have a functional $\mathcal{F}$ acting on some function $n(t)$ such that $$ \mathcal{F}[n(t)]=0 $$ $$ \mathcal{F}[n^*(s)n(t)]=\alpha(t,s) $$ $$ \mathcal{F}[n(s)n(t)]=0 $$ ...
3
votes
3answers
163 views

Trying to replace the text E with scientific notation

How to replace the E with scientific notation *^? ...
2
votes
1answer
54 views

Rewriting a plot expression to add an option works, but with an unexpected error message

I'm trying to rewrite a ListDensityPlot expression to systematiccaly add an option: ...
6
votes
3answers
114 views

Convert logical combinations from Reduce to a usable function

I'm working on a geometry problem and would like to create a function to create a triangle based on the logical constructs output by Reduce but cannot obtain all the constructs. Here's the problem: ...
3
votes
1answer
41 views

How to make function act on (multiple) replacement variables [closed]

I have a function which returns an algebraic expression corresponding to a "jump" between two ordinates, for example $[x]=x_2-x_1$. The function applies for any choice of variables and labels. The ...
4
votes
4answers
89 views

ReplaceList doesn't apply rules down to subparts

Somewhat related to a previous question, I'm experimenting with ReplaceList to get the list of all possible transformations we can obtain by applying a rule to an expression. But I don't manage to ...
1
vote
1answer
34 views

Annotating variables in replacement rules

How do you decorate or annotate a variable in a replacement rule? For example {(e[(-X + Y)^2 || f])} //. {e[(-a_ + b_)^2 || f] -> (-a + b)^2} Would ideally ...
3
votes
1answer
65 views

ReplaceRepeated with special characters: Alternatives

Following the advice here, I tried to replace part of an expression guided by the FullForm details: ...
2
votes
0answers
51 views

General rule to rewrite function and argument into a new symbol

I am trying to convert Mathematica output into equations I can plug into C. I am presently trying to convert expressions of the form Derivative[1,0,0][f][t,x,y] ...
3
votes
7answers
224 views

Obtaining the terms of a summation alongside the result

I have a Sum expression: s := Sum[2x,{x,0,3}] As an exercise to explore the rewriting capabilities of the Wolfram Language, I ...
2
votes
2answers
48 views

How to encode this rule (for visualization, etc) similar to cellular automata?

I came across this rule on Twitter and it reminded me of the cellular automota discussed in NKS: How to encode this in Mathematica for (visual) inspection?
4
votes
2answers
72 views

Extracting values from function/list containing arguments/elements (using patterns)

Here's an example input list: ...
0
votes
1answer
56 views

A single expression that performs substitution and simplifies a trigonometric form [closed]

I'm very new to Mathematica. I searched through the online documentation, but I don't understand why it realizes that $\sin(n\pi)$ for $n\in \mathbb{Z}$ is $0$: ...
0
votes
1answer
44 views

How to turn a matrix into a 'function'? [duplicate]

I have some codes to turn a set of equations into a matrix. Suppose the matrix Lis expressed in terms of variables $\epsilon$, $K$, $M$, and I want to make a ...
0
votes
1answer
51 views

Problem with replacement rules

I would like to apply substitution rules to an object I have defined, but I must be doing something wrong. Here are the relevant pieces of code. First I have defined a function ...
0
votes
2answers
60 views

Simplifying polynomial in one variable by substitution

I want to simplify a polynomial in variable $x$ with integer coefficients by substitution $x\to{x}/d$ so that the coefficients become smallest possible integers. Input: ...
2
votes
1answer
36 views

ReplaceRepeated multi-part pattern

This workaround does what I'd like to have happen: ...
0
votes
0answers
44 views

Delayed Rule right-hand-side mis-evaluation

Outline I am trying to create a rule that will give me a minus sign if the number of times A is applied on X is odd where A is some οperator and X a random quantity. Some of the configurations of ...
1
vote
1answer
38 views

Filter out terms that include any combination of F[X] and G[-X]

I have the following problem which is closely linked to a previous question I asked some time ago (Replacement rule for terms that are separated by operators?). In this specific instance, suppose I ...
0
votes
0answers
33 views

Rule Replacement Fails with Embedded Conditional

I was using a rule replacement that creates a matrix. At one rule, I added a conditional to return one vector and then added that (after the conditional and within the same replacement) to another. ...
1
vote
1answer
36 views

Replace expressions

Let's consider the following example ...
1
vote
0answers
36 views

The replacement function is an integral and the double integral yields a different answer than the normal double integral

I am fairly new to Mathematica. I have a quick inquiry. The code is simple and just 3 lines. Trying to do a replacement rule as follows ...
6
votes
1answer
90 views

ReplaceList Except Alternatives bug

Bug introduced in 11.3 or earlier and persisting through 12.0 or later [CASE:4352435] and [CASE:4354378] In Mathematica 11.3 and 12.0, ...
0
votes
2answers
71 views

Suppress arguments in output for pretty print

I would like to define a rule that suppress any arguments of a function for visibility. I tried: rule = f_[x__] -> f While this works well with individual ...
2
votes
1answer
58 views

Handling a list of variable assignments to be used with `With` [duplicate]

Is there a way to use With as follows? variables := {a = 2, b = 3}; With[variables, a^b] Desired output ...
0
votes
0answers
36 views

making replacements when patterns don't match exactly

I want to simplified some mathematical expressions, and they are similar to ...
1
vote
1answer
47 views

TagSetDelayed for spotting zero derivatives

I am trying to implement my own differential operator, d[arg_, var_], that computes the derivative of arg w.r.t. ...
0
votes
0answers
31 views

Tracing & Modifying a Function (Replace All) [duplicate]

For the function: f[x_Plus] := Apply[Times, x] f[a + b + c] Out[]= abc This is clear, as the Times is applied to the list with Plus head in f. However, when ...
1
vote
2answers
37 views

Manipulation replacements rules from Solve [closed]

Assume the call to the routine Solve[eqn==0,{x1,x2}] returns: {{x1->a1,x2->a2},{x1->b1,x2->b2}} I would like to ...
0
votes
0answers
37 views

Replacing in FeynCalc

I started to take the trace of some terms in FeynCalc package. I encountered a problem in replacing. Here is my problem: ...
3
votes
3answers
67 views

Assign Values from Array to Array [duplicate]

I am trying to simply do the following cVec = {a,b,c,d} From another expression, I obtain another vector, say, ...
0
votes
0answers
26 views

Variable subscript substitution - easy way?

I have a Mathematica expression with about 900 terms, that looks roughly like this: $X_{1,1} + Y_{1,2} + Z_{1,3} + XX_{1,4} + XY_{1,5} + ... $ Is it possible to perform a fast method to copy this ...
0
votes
0answers
39 views

Implementing a generic product rule

I'd like to implement a generic rule for expanding differential forms by the product rule. For instance, I'd like to transform the following PDE: $\phi \frac{\partial \phi}{\partial t} = \phi \nabla^...
3
votes
1answer
36 views

Prevent argument substitution in held expression when injecting into unevaluated code

I want to write a custom sow/reap pair to wrap any piece of code in sow[code] and call reap ...
0
votes
0answers
54 views

Derivative operator w.r.t a vector index and change of variables

Description and code lines: Define a scalar product to represent $A_i·A_j$ , $A_i ·B_j$ and $B_i ·B_j$, such that $A_i · A_i$ = 0. This is implemented in the following way: ...
1
vote
0answers
38 views

ReplaceAll on a Plot - Can you reproduce this error?

The weird thing is that it occurs only the first time I evaluate it! The same happens with Plot but not with Graphics. I can ...
0
votes
1answer
24 views

Plot with substitution of domain values before evaluation of function

I have a function of two variables $f(x,y)$. I find the maximum value of $f(x_0,y)$ by first substituting the value of $x=x_0$ and then maximizing in the range $0<y<1$. My question is: How to <...

1 2 3 4 5 22