4. Dynamic Interactivity

Mathematica has several  dynamic elements. It is very useful for visualization of the results if the problem contains some parameters and one wants to study it under the change of those parameters. You can study the following examples.

Example 1.

Manipulate[Show[Graphics3D[Point[{-1,1/2,1}],ViewPoint->{a,1,1}]],{a,-1,1}]

Example 2.

b

Dynamic[b]

Slider[Dynamic[b]]

Show[Graphics3D[Point[{1,1/2,1}],ViewPoint->{Dynamic[b],1,1}]]

Other examples.

Dynamic[n]

Slider[Dynamic[n]]

Dynamic[Plot[Sin[(n+1) x],{x,0,6}]]

DynamicModule[{x},{Slider[Dynamic[x],{1,5}],Dynamic[Plot[Sin[x i],{i,0,2Pi}]]}]

{Slider2D[Dynamic[x]],Dynamic[x]}

{InputField[Dynamic[x]],Dynamic[x]}

{,}

{Slider[Dynamic[1-y,(y=1-#)&]],Dynamic[y]}

{Slider[Dynamic[x]],Slider[Dynamic[1-x,(x=1-#)&]]}

Clear[x,n]

Manipulate[Factor[x^n-1],{n,10,100,1}]

Clear[a,b,c,x,y]

Manipulate[Plot[Sin[a x+b],{x,0,6}],{{a,2,"Multiplier"},1,4},{{b,0,"Phase Parameter"},0,10}]

Grid[{{a,b,c},{x,y,z}}]

Grid[{{a,b,c},{x,y^2,z^3}},Frame->All]

DynamicModule[{θ=0},Grid[{{Slider[Dynamic[θ],{0,100}],Dynamic@PolarPlot[t,{t,-Pi,θ},ImageSize->Tiny]}}]]

Manipulate[PolarPlot[θ,{θ,0,t},PlotRange->20],{t,1,6Pi}]

DynamicModule[{col=Green},EventHandler[Style["text",FontColor->Dynamic[col]],{"MouseClicked":>(col=Red)}]]

DynamicModule[{col=Green},EventHandler[Style["text",FontColor->Dynamic[col]],{"MouseClicked":>(col=col/.{Red->Green,Green->Red})}]]

interpolationCurve[p_,n_]:=Module[{x,f=Interpolation[p,InterpolationOrder->n ]},First@Plot[Evaluate@f[x],{x,Min[p[[All,1]]],Max[p[[All,1]]]}]];

DynamicModule[{n=2,p={},c={}},
EventHandler[Dynamic@Graphics[{Point[p],c},PlotRange->1,Frame->True],
"MouseDown" :> 
(p=Union[Sort@Append[p,MousePosition["Graphics"]],SameTest->(First[#1]==First[#2]&)];
If[Length[p] ≥n+1,c=interpolationCurve[p,n]])]]

Graphics[Locator[{0,0}],PlotRange->2]

DynamicModule[{p={0.5,0.5}},{Graphics[Locator[Dynamic[p]],PlotRange->2],Dynamic[p]}]

Manipulate[Graphics[Line[{{0,0},p}],PlotRange->2],{{p,{1,1}},Locator}]

Manipulate options

Quit[]

Manipulate[Plot[If[t,Sin[x],Cos[x]],{x,0,10}],{t,{True,False}}]

Manipulate[Plot[f[x],{x,0,2Pi}],{f,{Sin,Cos,Tan,Cot}}]

Manipulate[Plot[f[x],{x,0,2Pi}],{f,{Sin->"sine",Cos->"cosine",Tan->"tangent"}}]

Manipulate[Graphics[Line[{{0,0},p}],PlotRange->2],{{p,{1,1}},Locator}]

Manipulate[Graphics[Polygon[pt],PlotRange->2],{{pt,{{0,0},{1,0},{1,1},{0,1},{1,-1}}},Locator}]

Manipulate[ParametricPlot[{Sin[t+d[[1]]],Sin[t+d[[2]]]},{t,0,2Pi}],{d,{0,0},{Pi,Pi}}]

Manipulate[Plot[f[x],{x,0,10}],{f,Tan}]

Manipulate[Graphics[{color,Disk[]}],{color,Purple}]

Manipulate[{x1,x2,x3},{x1,0,1},{x2,{1,2,3}},{x3,{True,False}}]

{Manipulate[Plot[f[x],{x,0,2Pi}],{f,{Sin,Cos,Tan,Cot}}],Manipulate[Plot[f[x],{x,0,2Pi}],{f,{Sin,Cos,Tan,Cot},ControlType->PopupMenu}]}

Manipulate[x,{{x,0},Button["random",x=RandomReal[]]&}]

Manipulate[x,{{x,1},0,5},{x,Range[5]}]

Manipulate[Block[{f=F[x+I y]},ParametricPlot[Evaluate[{Re[f],Im[f]}],{x,-Pi,Pi},{y,-2,2}]],{F,{Sin,Tan,Cot}}]

Quit[]

Manipulate[Plot3D[Sin[n x y],{x,0,3},{y,0,3}],{n,1,4,0.5}]

Manipulate[ParametricPlot3D[{Cos[v]+0.3 Sin[n u]+0.04 Sin[20 v],u,Sin[v]+0.3 Cos[m u]+0.04 Sin[20 v]},{u,-π,π},{v,-π,π},PlotPoints->50,Mesh->mesh,Axes->axes,Boxed->boxed],
{n,1,5},{m,1,5},
{mesh,{None,Automatic,All}},
{axes,{False,True}},
{boxed,{False,True}}]

Quit[]

Manipulate[Module[{x},With[{sol=NDSolve[{x''[t]+x[t]^3==α Sin[ω t+β],x[0]==pt[[1]],x'[0]==pt[[2]]},x,{t,0,50}]},ParametricPlot[{x[t],x'[t]}/.sol,{t,0,t1},PlotRange->5]]],
{α,-3,3},{β,-π,π},{ω,1,5},{t1,10,50},{{pt,{0,0}},Locator},SaveDefinitions->True]

Manipulate[Plot[Evaluate[Sum[(1/(((k+1))^i)),{k,0,n}]],{n,0,100},PlotRange->All],{i,1,10,1}]

Manipulate[PolyhedronData[poly],{poly,PolyhedronData[]}]

Manipulate[With[
{img=ImageAdjust[,{contrast,brightness}]},Column[{ImageHistogram[img],Image[img,ImageSize->All]}]],
{{brightness,0},-1,1},{{contrast,0},-1,1}]