Hello guys,
How to replace the variables of an expression without being evaluated?
For example:
x = 2; y = 3; z = 5; (x + y) / z
Show (2 + 3) / 5 instead of 1
Hello guys,
How to replace the variables of an expression without being evaluated?
For example:
x = 2; y = 3; z = 5; (x + y) / z
Show (2 + 3) / 5 instead of 1
In[1]:= Defer[(x + y)/z] /. {x → 2, y → 3, z → 5}
Out[1]= (2 + 3)/5
Another way
Clear[x, y, z]; HoldForm[(x + y)/z] /. {x -> 2, y -> 3, z -> 5}
To calculate the expression use
ReleaseHold[%]
You may define a function and use it:
In[1]:= f[x_, y_, z_] := Defer[(x + y)/z]
In[2]:= f[2, 3, 5]
Out[2]= (2 + 3)/5
Use your approach and work very well
With Defer also works
thanks guys