1
$\begingroup$

How can one do this:

Manipulate[ 
 Plot[  -Log[
    1 - s x + (s^2 x^2)/2 - ((4 c - 4 s^2 + s^4) x^3)/(
     4 (-3 + 2 s)) + (s (8 c - 8 s^2 + 3 s^3) x^4)/(8 (-3 + 2 s)) - (
     s (8 c - 8 s^2 + 3 s^3) x^5)/(20 (-3 + 2 s))    ], {x, -2, 
   2} ], {c, 0.01, 0.2}, {s, 0.1, 1.5}]

(which works fine) without explicitly having the expression in the manipulate statement. It is not obvious from the link so I fail to see how this is a duplicate.

For example, why doesn't this work?

rule = { z -> -Log[
      1 - s x + (s^2 x^2)/2 - ((4 c - 4 s^2 + s^4) x^3)/(
       4 (-3 + 2 s)) + (s (8 c - 8 s^2 + 3 s^3) x^4)/(
       8 (-3 + 2 s)) - (s (8 c - 8 s^2 + 3 s^3) x^5)/(
       20 (-3 + 2 s))] };
Manipulate[
  Plot[z /. rule, {x, 0, 10}],
             {c, 0.1, 0.5},
             {s, 0.1, 0.4}
 ]

I'd like to know what to do if

i) I have a function f[x,c,s] . This is what I've tried:

f[x_, s_, 
  c_ ] = -Log[ 
   1 - s x + (s^2 x^2)/2 - ((4 c - 4 s^2 + s^4) x^3)/(
    4 (-3 + 2 s)) + (s (8 c - 8 s^2 + 3 s^3) x^4)/(8 (-3 + 2 s)) - (
    s (8 c - 8 s^2 + 3 s^3) x^5)/(20 (-3 + 2 s))]
Manipulate[ Plot[ f[x, c, s], {x, -2, 2} ],
      {c, 0.1, 0.3},
      {s, 0.1, 0.5} 
 ]

ii) I have an expression in x, c,s

$\endgroup$
4
  • $\begingroup$ I may be missing something here, but if you have a well defined function f[x,c,s] all you have to do is put f[x,c,s] as Plots first argument. All the necessary variables are visible to Manipulate then and it it should just work as explained in Karsetn's link. $\endgroup$ Dec 17, 2014 at 20:34
  • $\begingroup$ In your latest update you haven't put any visible references to x, c, and s in the expression, which is necessary. Again, this is explained in the link. $\endgroup$ Dec 17, 2014 at 20:36
  • 1
    $\begingroup$ What's your problem with case i)? It works as expected. For your second case, you have to make the variables visible. Just define g[x_, s_, c_] = z /. rule outsize of the manipulate or with its Initialization option and use g[x, c, s] in the plot. $\endgroup$ Dec 17, 2014 at 20:47
  • $\begingroup$ Your block of code in the middle works, if you use With[{rule = rule}, Manipulate[Plot[z /. rule, {x, 0, 10}], {c, 0.1, 0.5}, {s, 0.1, 0.4}] ], as shown in the possible duplicate. $\endgroup$
    – Karsten7
    Dec 17, 2014 at 21:16

0

Browse other questions tagged or ask your own question.