Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'A More flexable demonstration' topicStudent Support Forum > General > "A More flexable demonstration"

Help | Reply To Topic
Author Comment/Response
Josh Fritz
08/29/07 1:21pm

Hello,

I change the code below so that when I choose a specific function on the Pop up menu everything is constrained to the function chosen. Sort of like an If[ funciton1 chosen] do this code, If[fucntion2 chosen] do a different set of. How can I set it up so that only certain code is executed base upon which function is selected from the Pop up menu. Here is my code so far. I am trying to change one the demonstrations posted on the wolfram website to be more flexable. Sorry, it is a bit exhaustive:





f[x_] := 3 (x - 1)^(1/3) - 2;
finv[y_] = 1/27 (35 + 12 y + 6 y^2 + y^3);
p = 3 (x - 1)^(1/3) - 2;

xmax = 10; ymax = 5;

Manipulate[
DynamicModule[{pt = {xxx, f[xxx]}, pt2 = {1, 0}, pt3 = {9, 0}},
Deploy[Labeled[Column[{
LocatorPane[

Dynamic[{pt, pt2, pt3}, {(pt = {#[[1, 1]], f[#[[1, 1]]]};
xxx = #[[1, 1]];
pt2 = {#[[2, 1]], 0};
pt3 = {#[[3, 1]], 0}) &}],

ptx = Dynamic[pt[[1]]]; pty = Dynamic[pt[[2]]];
pt2x = Dynamic[pt2[[1]]]; pt2y = Dynamic[pt2[[2]]];
pt3x = Dynamic[pt3[[1]]]; pt3y = Dynamic[pt3[[2]]];

mandist1 = Dynamic[Abs[pt2[[1]] - xxx]];
mandist2 = Dynamic[Abs[pt3[[1]] - xxx]];

Deploy[Show[
Plot[graph, {x, 0, xmax},
PlotStyle -> {Blue, Thickness[.007]}],

Graphics[{
{Thickness[.005], Lighter[Gray, 0.5],
Line[{{ptx, 0}, {ptx, ymax}}],
Line[{{0, pty}, {xmax, pty}}]},
{Orange, Thickness[.006],

If[autodelta, {Line[{{finv[pty - ep], 0}, {finv[pty - ep],
ymax}}],
Line[{{finv[pty + ep], 0}, {finv[pty + ep], ymax}}]},
{Line[{{pt2x, 0}, {pt2x, ymax}}],
Line[{{pt3x, 0}, {pt3x, ymax}}]}]},
{Thickness[.006], Darker[Green, 0.5],
Line[{{0, pty - ep}, {xmax, pty - ep}}],
Line[{{0, pty + ep}, {xmax, pty + ep}}]},
{Black, PointSize[0.02], Point[{Dynamic[pt]}]},(*{Text[
Style["c",Italic,16],{ptx,0.3}]},*)
{Text[Style["L", Italic, 16], {0.3, pty}]}
}], PlotRange -> {{0, xmax}, {0, ymax}},
ImagePadding -> 10, ImageSize -> 600,
Ticks -> {Union[Table[{n, n}, {n, 0, xmax}],
Table[{n, ""}, {n, 0.5, xmax, 1}]],
Union[Table[{n, n}, {n, 0, xmax}],
Table[{n, ""}, {n, 0.5, xmax, 1}]]}]], {{1.25, 1.25}, {10,
5}}, Appearance -> Style["\[FilledCircle]", Opacity[0]]],

Text@
Style[Row[{" \[CurlyEpsilon] = ", ep}], 20,
Darker[Green, 0.5]],
Text@
Style[Row[{StringJoin[" ",
ToString[Subscript[\[Delta], 1], TraditionalForm], " = "],

If[autodelta, Dynamic[N[Abs[finv[f[xxx] - ep] - xxx]]],
mandist1],
StringJoin[" ",
ToString[Subscript[\[Delta], 2], TraditionalForm], " = "],

If[autodelta, Dynamic[N[Abs[finv[f[xxx] + ep] - xxx]]],
mandist2]}], 20, Orange]
}],
Text@Style[
Row[{TraditionalForm[HoldForm[f[x]]], " = ",
Style[TraditionalForm[p], Italic]}], 20], Top]]
],

{{graph, 3 (x - 1)^(1/3) - 2,
""}, {3 (x - 1)^(1/3) - 2 -> TraditionalForm[3 (x - 1)^(1/3) - 2],
3 x + 4 -> TraditionalForm[3 x + 4],
x^2 + 1 -> TraditionalForm[x^2 + 1]}, ControlType -> PopupMenu},
{{ep, 1, Style["\[CurlyEpsilon]", 16]}, 0, 2,
ControlType -> VerticalSlider, ControlPlacement -> Left},
"None" -> {{autodelta, True,
"automatically calculate \[Delta] values"}, {True, False},
ControlPlacement -> Bottom},
"None" -> {{xxx, 5}, 0, xmax, ControlType -> None},
TrackedSymbols :> {ep, autodelta, graph}, AutorunSequencing -> {1}]

Attachment: FiniteLimitAtAFinitePointHW.nb, URL: ,
Help | Reply To Topic