Questions tagged [replacement]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4 votes
2 answers
47 views

Replacement question

I have this equation F2 + F4 - V1 + V3==0 I want it to be converted automatically via a replacement rule to ...
  • 1,203
1 vote
2 answers
211 views

How to define replacement rule for Minkowski inner product

following question, I have an expression that consists of several Minkowski inner products between 2 four vectors written as in Mathematika: ...
0 votes
0 answers
29 views

Get Complete form of a function from a nested definition [closed]

I have pretty basic question. Assume the Following system: F[x]:=2*x G[x]:=2*F[x] How do I substitute F[x] in ...
  • 101
2 votes
2 answers
81 views

Replacing symbolic variables inside of a compile

As the result of a symbolic integration, I have a very long array with symbolic variables u[i] which I would like to substitute for real number values. Moreover, I ...
  • 43
0 votes
0 answers
29 views

Simplifying a Given PDE Expression [closed]

I have an expression for the $2D$ velocity of a fluid, given by: $$ \vec{u} = -(k+k_0)[\nabla p-\frac{\delta \mathcal{F}}{\delta \phi}\nabla\phi]-k_0(1-\phi)\nabla\frac{\delta \mathcal{F}}{\delta \phi}...
  • 221
0 votes
0 answers
24 views

Non-Dimensionalizing PDEs using Mathematica [duplicate]

I am attempting to non-dimensionalize the following equation: $$ \vec{u}=-(k+k_0)\left[\nabla p -(f'(\phi)-\epsilon^2\nabla^2\phi)\nabla\phi \right]-k_0(1-\phi)\nabla(f'(\phi)-\epsilon^2\nabla^2\phi)-\...
  • 221
2 votes
3 answers
91 views

Replace repeated items differently

So I have a simple replacement rule of the following form: expr/.f[a_,b_]:> g[a,#]g[b,#]&@func[] i.e. I want to replace each function f[a,b] with two ...
  • 651
3 votes
1 answer
76 views

Transforming A Complicated Expression

I am trying to transform an expression according to these rules I've defined: $$ L_1^m L_2^n L_3^p L_4^q \rightarrow \frac{m!n!p!q!}{(m+n+p+q+3)!}6V \\ \text{constant } k \neq 0 \rightarrow kV$$ Some ...
5 votes
1 answer
108 views

Function with optional argument that depends on other argument

I'm trying to do a simple thing: I want the optional argument to depend on another argument, i.e. f[x_,y_:Subscript[m,x]] := x-y This should give: ...
  • 651
4 votes
3 answers
265 views

Simplify with given equality

Clear[id, kn, vt, vdd, vo]; id = kn*(vi - vt)^2/2; vo = vdd - id*rd; Solve[D[vo, vi] == -1, vi] Output: ...
  • 143
3 votes
2 answers
145 views

How to replace generic function with another one?

I have complicated expression in terms of derivatives of a multivariable function F[x,y,z] say ...
  • 33
0 votes
1 answer
86 views

Replacing a term according to a given criterion in an expression with non-commutative multiplication (for any sign and location)

There is the following expression: ...
  • 1,881
1 vote
2 answers
98 views

Replace with non-commutative product

I'm trying to evaluate some scattering amplitudes terms in Mathematica using the spinor helicity formalism. For that, I need to turn products like $\epsilon_i\cdot k_j$ into spinor product which can ...
  • 209
19 votes
1 answer
743 views

When did this global rules change happen in Mathematica? Is this change documented?

In this Wolfram talk video titled "Professor Richard J. Gaylord's Wolfram Language Fundamentals Part Two" he shows at time 36:45 the following Where there are two definitions for ...
  • 115k
2 votes
1 answer
54 views

How to do the following symbolic substitution?

In the algorithm that I am trying to implement, I have the following symbolic substitution to be done $z^{-2 n} \rightarrow \frac{(i t)^{2 n-1}}{(2n-1)!} $. I tried to do the above as ...
  • 155
3 votes
1 answer
75 views

How to Programmatically Replace a Word in a Text Cell with a Button (for popup definitions)

I am attempting to create popup definitions for important words in my lecture notebooks. I plan to create a glossary containing a list of words and their definitions and then search through my lecture ...
  • 4,825
0 votes
0 answers
37 views

Finding variables that are arbitrary (undefined) functions of other variables with arbitrary names (such as n1, n2,n3)

I have expressions that could look like: $$ n = n0 + n1[x,\tau_0, \tau_1]+n2[x,\tau_0, \tau_1]+n3[x,\tau_0, \tau_1]+ \dots$$ Where the $n_i$ are undefined functions of the variables listed inside ...
  • 1
1 vote
1 answer
54 views

Replacement Rules and Function Definitions

I have this code currently: ...
  • 221
2 votes
1 answer
63 views

Expression involving If and /. gives different result from direct evaluation

...
  • 121
1 vote
0 answers
53 views

How to get rid of "/." in my result, when I evaluate a term containing ReplaceAll?

In the previous code I defined Bchoice and pchoice In one line I defined ...
  • 111
6 votes
3 answers
251 views

Replace items of list except items that are member of another list

I want to replace all items in li1 that are not members of li2 with x. ...
  • 3,735
0 votes
0 answers
32 views

Algebraic substitutions not working? [duplicate]

I have been trying to simplify this matrix $$ \left( \begin{array}{cc} \frac{1}{2} \left(-2 g \sqrt{1-\text{tauA}} \sqrt{1-\text{tauB}}+\text{mu} \text{tauA}+\text{mu} \text{tauB}+\text{...
2 votes
2 answers
55 views

Why is first substituting for the known variable and then solving for an unknown variable, using Solve[], correct whereas doing the reverse is wrong?

Consider the following code: (*Initializations*) c=10; f=Log[1+c]-c/(1+c) I am trying to figure out whether I should first substitute for ...
0 votes
0 answers
43 views

Transforming $e^{m i\beta+n i \gamma}$ into $x^m y^n$

I want to write code to transform $e^{m i\beta+n i \gamma}$ into $x^m y^n$, where $m,n\in \mathbb{Z}$. For example, I write the follow code when $m=3,n=2$: ...
4 votes
1 answer
85 views

How to generate a list of lists from a given list following a rule recursively?

Assume that I have made the following rule: Rule: {x1,x2,x3,x4,x5,x6,x7,x8} -> {x1,x2,x3,x4,x5,x6,x7,x8}, {x4,x5,x6,x1,x2,x3,x7,x8}, {-x1,-x2,-x3,-x4,-x5,-x6,x7,x8}, {x1,-x2,x3,x4,-x5,x6,-x7,-x8}...
  • 2,151
5 votes
3 answers
275 views

Making algebraic substitutions with approximations

I'm struggling to make a substitution in a symbolic expression where I want to use an approximation. For example if we have the equation $$\frac{1}{a}\frac{c}{a - b} = \frac{c}{a^{2} - a b} \approx \...
  • 2,366
21 votes
3 answers
1k views

What is the fastest method to set the diagonals of a matrix to 1?

I am trying to replace the zeros along diagonal of a distance matrix to a list of constants. In this case, a diagonal of 1's. It appears that the LinearAlgebra ...
  • 2,779
0 votes
0 answers
58 views

Back-substitution

Suppose that we have an expression (expr in the code below) and replace a long term with a new parameter (K). For a simple example; ...
  • 507
1 vote
1 answer
56 views

function/module to achive a replacement as follows

I want to shorten some long expressions by using some new parameters. So, I want to create a function/module to achive a (multiple) replacement as follows: ...
  • 507
3 votes
1 answer
93 views

Use rules on list elements one by one [closed]

I have two list list1 = {1, 1, 2, 4, 1, 1, 8, 7}; list2 = {a, b, c, d, e, f, g, h}; I want to build rule,...
1 vote
1 answer
33 views

Keep arguments of a function unevaluated after replacement rules

Consider an expression of type f[a,b]+a+b and a set of replacement rules sub={a->1,b->2} If I evaluate now the ...
  • 131
1 vote
0 answers
27 views

Replace subexpression with variable in result from Laplace transform

I'd like to clean up the result I obtained from an inverse Laplace transform: First of all, I'd like to replace the square root expressions in the hyperbolic function arguments (part encircled in ...
  • 11
1 vote
0 answers
31 views

Using ReplaceAll to simplify derivatives

I'm struggling trying to simplify the derivative of a function. I know that ReplaceAll works like that: What I want is to replace the function itself that should ...
1 vote
2 answers
51 views

How can I collect the sum of any number of gradients without using ReplaceRepeated[]?

Recently, I have run into the problem where I need to collect the the sum of any number of gradients. I have defined a function grad[] to represent the gradient, ...
  • 443
0 votes
0 answers
38 views

How to replace functions with their Fourier transform [duplicate]

I have a function \deltaG given by ...
7 votes
8 answers
452 views

How to replace anti diagonal elements of a matrix

I want to assign new values to the anti-diagonal elements of a square matrix m with the values of its diagonal elements. For that, I want to make use of ...
  • 319
3 votes
2 answers
125 views

Replacing a trigonometric value

It looks like MMA cannot evaluate Tan[42°] but it can be written as (-Sqrt[6 - 2 Sqrt[5]] + Sqrt[6 (5 + Sqrt[5])])/(2 Sqrt[7 - ...
  • 1,273
4 votes
1 answer
44 views

Timing Discontinuity with Replace[] Function

When constructing certain square matrices I noticed a sharp jump in the time required to build them. I've included code and a plot of time required to make the matrix vs dimensionality of the matrix. ...
5 votes
4 answers
581 views

Replacing large numbers

Imagine I have the following list l = {{1,2,3},{4,10^(16),5}} How do I efficiently replace the large number by a number (zero, for example). I can't seem to do it ...
  • 4,388
8 votes
2 answers
116 views

Constructing a RootSum object changes existing internal syntax

Bug introduced in 9.0 or earlier and persisting through 13.0.1 or later I noticed that initially valid syntax becomes invalid within nested RootSum objects. ...
  • 2,939
4 votes
3 answers
211 views

How to use a rule such that it substitutes the value x and derivatives of x in the expression?

For example, I have gotten the value for a certain function H[t,r]: $H[t,r] \to -\frac{2r(K[t,r]+K^{(0,1)}[t,r]+2m+r+...)}{(2m-r)}$ I want to replace its value, ...
8 votes
2 answers
313 views

Simple, fast re-defining a part of 2D list

A[[{2, 3, 5}]] = {97,98,99} changes 2,3,5-th elements of A to 97,98,99 respectively. Similary A[[{2, 3, 5}]] = 100 changes 2,3,...
  • 3,221
2 votes
1 answer
28 views

MatchQ returns False for a match for e1 ** e2 while matching both e1 and e2

I used a simple predicate realQ[x_] := MemberQ[{Real, Integer, Rational}, Head[x]]. With that predicate both ...
  • 21
2 votes
1 answer
58 views

Can substitution rules be used in function definitions?

Simple input like this f[x_]:=2x f[2] has the predicted output of 4. However, this r={a->2x}; f[x_] := a/.r f[2] Produces ...
  • 187
0 votes
1 answer
58 views

FindFit with Replace error

I am trying to fit my data, and I keep having error messages as below. Could anybody help me to solve this problem? The codes are written after the error messages. ...
3 votes
1 answer
75 views

Terms of expressions with non-commutative multiplication that meet the given criteria

There is the following expression: expr=a^3**x**Transpose[x]**y+x+y**Transpose[y]**x**a^3+x**Transpose[y] It is necessary to apply the ...
  • 1,881
7 votes
7 answers
425 views

'Mapping' the values of a list to variable

Suppose I have the variable expr1 = a[n] + b[n], and the list stencil={-1,0,1}. I want to make a function ...
  • 957
0 votes
0 answers
41 views

Replace Derivative[ i ][ f ][ t ] with f[ i, t]

Assume the PadeApproximant is carried over f[t0] * g[t0] with the order {1, 1}, that is <...
4 votes
2 answers
189 views

Tropical Operation Conversions: Multiple Operations

I apologize if my syntax is bad. I looked around, but didn't see anything on this in the stack exchange. I would like to be able to transform a classical real-valued polynomial to a tropical ...
  • 143
4 votes
1 answer
75 views

Replacement, PatternTest, Module related Question

Let's see how MMA handles following type of expression : Replace[L, {pattTest1->rhs1, pattTest2->rhs2, pattTest3->rhs3}, {1}] Specific example : ...
  • 3,221

1
2 3 4 5
30