1
$\begingroup$

Here is my attempt to manipulate the value of q for the PDF function. Whenever I use the manipulate function, nothing happens to the output. Can anyone explain why?

my code for the manipulate function

$\endgroup$
0

3 Answers 3

3
$\begingroup$

You have many code errors, such as the error in defining a function G[x_]= instead of G[x_]:=, the fact that sigma cannot have a value (because q is not assigned), missing semicolons, and much more.

I presume you're lifting my code from here.

Anyway, here is your answer:

Manipulate[
 Integrate[
  PDF[
      NormalDistribution[0, -q Log[2, q] - (1 - q) Log[2, 1 - q]], x], 
  {x, 0, 1}], 
  {q, .1, .3}]
$\endgroup$
3
  • $\begingroup$ Yes, I was the one who asked the previous question as well. $\endgroup$
    – sde7
    Sep 15, 2018 at 20:28
  • 1
    $\begingroup$ ...and never accepted my previous answer. $\endgroup$ Sep 15, 2018 at 20:32
  • $\begingroup$ I just recently made an account. $\endgroup$
    – sde7
    Sep 15, 2018 at 20:36
1
$\begingroup$

You have a variable scoping problem. The global q that appears in your definition of sigma is not the same as the local q that appears in your Manipulate expression. One way to fix it is:

sigma[q_] := -q Log2[q] - (1 - q) Log2[1 - q]
g[q_][x_] := PDF[NormalDistribution[0, sigma[q]], x]
Manipulate[g[q][x], {q, .0001, 1}]
$\endgroup$
0
$\begingroup$

Manipulate doesn't "see" the q term in the argument.

To fix this use

Manipulate[PDF[NormalDistribution[0, sigma], x] /. q -> Q, {Q, 0, 1}]

Or make sigma a function of q as

sigma[q_] := -q Log[2, q] - (1 - q) Log[2, 1 - q]
Manipulate[PDF[NormalDistribution[0, sigma[q]], x], {q, 0, 1}]
$\endgroup$
1
  • $\begingroup$ I made this change. It does work. However, part of the input is to integrate the PDF function G[x]. It does not make the change in Out[54] whenever I manipulate q. Any ideas? $\endgroup$
    – sde7
    Sep 15, 2018 at 20:23

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