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?
Asked
Active
Viewed 137 times
3 Answers
3
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}]
David G. Stork
- 41,180
- 3
- 34
- 96
-
Yes, I was the one who asked the previous question as well. – sde7 Sep 15 '18 at 20:28
-
1...and never accepted my previous answer. – David G. Stork Sep 15 '18 at 20:32
-
I just recently made an account. – sde7 Sep 15 '18 at 20:36
1
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}]
m_goldberg
- 107,779
- 16
- 103
- 257
0
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}]
NonDairyNeutrino
- 7,810
- 1
- 14
- 29
-
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? – sde7 Sep 15 '18 at 20:23
