Message Boards Message Boards

0
|
2440 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Variable replacement in only parts of an expression

Posted 10 years ago

Hi!

Suppose I have an expression like $A = ( Log[s+t] + s^2 + t ~s + u )$. I want to substitute $s$ by $a$ and $t$ by $b$ ONLY inside $Log[s+t]$ without affecting the remaining part. Is there any way to do this? If we directly substitute $s$ by $a$ and $t$ by $b$ then Mathematica will do the substitution in every places but I want to substitute only in some selected places namely only in the arguments of a function. How can I do that? Hope the problem is clear.

Thank you.

POSTED BY: Taushif Ahmed
2 Replies
Posted 10 years ago

.

In[1]:= A = (Log[s + t] + s2 + t s + u);A /. Log[s + t] -> Log[a + b]

Out[2]= s2 + s t + u + Log[a + b]
POSTED BY: Bill Simpson

Or

In[2]:= (Log[s + t] /. {s -> a, t -> b}) + s2 + t s + u

Out[2]= s2 + s t + u + Log[a + b]
POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract