0

Imagine I have defined a variable l=p/(a*b) Let's say I perform some operations, and I get the final answer to be p/a. But all I really care about is how this expression looks in terms of l and b. Is there a way to use the relation l=p/(a*b) to convert p/a to l/b?

Of course this is a very trivial example, it gets trickier when you have other, more complicated relations. I have tried the replace command /.{p/(a*b) -> l} but it does not work.

I would appreciate any advice you have!

megamence
  • 101
  • 1

1 Answers1

0

Once you have your answer, ans, you can Unset variable l and use it in subsequent expressions, to get a new answer, like this

Clear[a, b, l, p]

l = p/(a*b);

ans = p/a;

auxEqn = l == (l =.; l);

newAns = ans /. First@Solve[auxEqn, p] (* bl *)

Now newAns evaluates to b*l and l no longer has a value. If you want to recover the value of l from auxEqn, do this

Set @@ Reverse@auxEqn;
l   
  (*  p / (a b)  *)

But, if you do that, newAns will evaluate to p/a. Unless you Unset[l] (same as l=.) again, in which case newAns will evaluate to b*l.

If you were really going to do something like this, consider starting with auxEqn = l == p/(a*b). Then you would Set@@auxEqn to set the value of l, do the calculations that need l to have a value, and l=. to unset the value. Once l is unset, use Solve[newEqn, p] to replace parameter p with its equivalent expression involving l.

LouisB
  • 12,528
  • 1
  • 21
  • 31