Hello,
I have a question about Mathematica. If I have an expression like "f[x,y,z]+x*g[x,y,z]” and I want to set x=0 but not inside the function f[x,y,z] and g[x,y,z], only for terms linearly dependent in x, is there a function that allows me to do so?
Thank you,
Martina Cottini
Hi Martina,
Do you mean something like this
ClearAll[x, y, z, f, g]
exp = f[x, y, z] + x*g[x, y, z]
exp /. Coefficient[exp, x] -> 0
(* f[x, y, z] *)
exp2 = f[x, y, z] + x^2*g[x, y, z]
exp2 /. Coefficient[exp2, x] -> 0
(* f[x, y, z] + x^2 g[x, y, z] *)
Thank you for the answer. Actually I am looking for something more general because my expression contains not only “xg[x,y,z]” but also “x^2h[x,y,z]” etc and I want to set x=0 in every case but not in the functions f[x,y,z],g[x,y,z],h[x,y,z] etc.
I attach the function for a better comprehension of the problem. In my example I want to set lambda^2=0, lambda^4=0 every where except in the functions B0,C0.
thanks, Martina
Welcome to Wolfram Community! Please make sure you know the rules: https://wolfr.am/READ-1ST
The rules explain how to format your code properly. Images don’t help other members to copy your code. Please EDIT your comment and make sure code blocks start on a new paragraph and look framed and colored like this.
int = Integrate[1/(x^3 - 1), x];
Map[Framed, int, Infinity]
You can also embed notebook or attach notebook.
Martina,
You would need to “protect” the function calls from the replacement of x. I would do a temporary replacement by removing x from the function calls and return it back after setting x to zero. For example:
In[9]:= exp2 = f[x, y, z] + x^2*g[x, y, z] + x*g[x, y, z]
Out[9]= f[x, y, z] + x g[x, y, z] + x^2 g[x, y, z]
In[6]:= newexp =
exp2 /. {f[x, a_, b_] -> fx[a, b], g[x, a_, b_] -> gx[a, b]}
Out[6]= fx[y, z] + x gx[y, z] + x^2 gx[y, z]
In[8]:= newexp /. x -> 0 /. {fx[a_, b_] -> f[x, a, b],
gx[a_, b_] -> g[x, a, b]}
Out[8]= f[x, y, z]
Regards,
Neil
It is really hard to see where λ^2 and λ^4 appear in the expression. Please include the text for the InputForm of Out[53].
InputForm @ %53
…and what about an additional variable?
exp[x_, y_, z_, u_] := f[x, y, z] + u*g[x, y, z]
exp[x, y, z, x]
exp[x, y, z, 0]

