Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Manipulate in a series of commands
Replies: 0

 Lengyel Tamas Posts: 10 Registered: 2/23/11
Manipulate in a series of commands
Posted: Oct 19, 2011 5:01 AM

Dear Community,

I am faced with a probably very easy problem. At the bottom you can see my
code which executes in a single cell once the parameter K is set to an
integer number greater than 0.

I can't seem to make it Dynamic or use Manipulate, e.g. have a slider or
text box where I can change the number K, then have the series of commands
executed.
Any ideas?

Tamás

Code:

K = 64;
Element[n, Integers];
Degen = Piecewise[{{0,
n < -K}, {(K - Ceiling[(K - n)/2]), -K <= n <=
0}, {(K - 1 - Floor[n/2] - Ceiling[(K - n)/2]),
0 < n <= K}, {(K - Floor[n/2]), K < n <= 2 K}, {0, n > 2 K}}];
g1 = DiscretePlot[Degen, {n, -K, 2 K}, AxesOrigin -> {-K, 0},
PlotRange -> {{-K, 2 K}, {0, K^2/2.5}},
PlotStyle -> {Thickness[0.01]},
FillingStyle -> RGBColor[0.4, 1, 0.4, .9]];
NonDegen =
Piecewise[{{0,
n < -K}, {(Ceiling[(K^2 + n^2 - 2*K - 2 n + 2*K*n)/4]), -K <=
n <= 0}, {(Ceiling[(K^2 - 6 K - 2 n^2 + 2 n + 4)/4 +
Floor[(K*n)/2]]),
0 < n <= K}, {(Floor[(4 K^2 + n*n - 4 K*n)/4]),
K < n <= 2 K}, {0, n > 2 K}}];
g2 = DiscretePlot[Degen + NonDegen, {n, -K, 2 K},
AxesOrigin -> {-K, 0}, PlotRange -> {{-K, 2 K}, {0, K^2/2.5}},
PlotStyle -> {Thickness[0.01]},
FillingStyle -> RGBColor[0.01, 0.01, 2, 1]];
g3 = DiscretePlot[((K/2 - 1) + (K^2 - 6*K + 2*K*n - 2 n^2 + 2 n + 4)/
4), {n, 1, K}, AxesOrigin -> {-K, 0},
PlotRange -> {{-K, 2 K}, {0, K^2/2.5}},
ColorFunction -> (RGBColor[#2, 0.2, 1 - #2] &),
FillingStyle -> {Directive[{Thickness[0.01], Opacity[0.9] }]},
Filling -> Axis];
Show[g2, g3, g1, AxesLabel -> {"n", "Number of FWM products"},
LabelStyle -> Directive[Black, Bold, 14]]
max = FindMaxValue[((K/2 - 1) + (K^2 - 6*K + 2*K*n - 2 n^2 + 2 n + 4)/
4), n];
Floor[max]