0
$\begingroup$

For example, I have a function

W[L_, m_] := 1 + 3 L + 2 L^2 - 6 m - 6 Lm + 6 m^2

I also have

r = m/L

What is the easiest way to plot W-function from r?

Now I just manually plug in expression for r in W and obtain

W[L_, r_] := 1 + 3 L + 2 L^2 - 6 r*L - 6 L (r*L) + 6 (r*L)^2

Is there any other way to do that?

$\endgroup$

1 Answer 1

0
$\begingroup$

Note that you should not use upper-case letters for variables or names beginning with upper-case letters as they might conflict with Mathematica's internal names.

w[l_, m_] := 1 + 3 l + 2 l^2 - 6 m - 6  l m + 6 m^2

z[l_, r_] := w[l, m] /. m -> r l

w[l, m]

(* 1 + 3 l + 2 l^2 - 6 m - 6 l m + 6 m^2 *)

z[l, r]

(* 1 + 3 l + 2 l^2 - 6 m - 6 l m + 6 m^2 *)

$\endgroup$
6
  • $\begingroup$ Or just w[l, r*l]. $\endgroup$
    – march
    Nov 5, 2015 at 17:40
  • $\begingroup$ @march I interpretted Maria's question to require a function (with slots) with the substitution. But yes... if you need merely compute w with the substitution, your answer is fine. $\endgroup$ Nov 5, 2015 at 17:42
  • $\begingroup$ True. But it's always worth letting the new users see multiple ways of doing things of course. But I think you accidentally removed the edit I made: r -> r l should be m -> r l, as illustrated by the output of z[l, r] that you copy-and-pasted. $\endgroup$
    – march
    Nov 5, 2015 at 17:44
  • $\begingroup$ Should it be ` r -> m/l` ? Is there any difference if I write z[l_, r_] := w[l, m] /. m -> r l or z[l_, r_] := w[l, m] /. r -> m/ l ? $\endgroup$
    – Mary
    Nov 5, 2015 at 17:48
  • 1
    $\begingroup$ @Maria. You should experiment with the different expression that you've written down and see which one works! It's the best way to learn Mathematica. $\endgroup$
    – march
    Nov 5, 2015 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.