(* Style Definitions *)
titleStyle = {FontFamily ->"Liberation Sans",14,Bold, RGBColor[0.35,0.35,0.35],Background->RGBColor[1,1,1,0]};
textStyle = {FontFamily ->"Liberation Sans",12,Bold, RGBColor[0.35,0.35,0.35],Background->RGBColor[1,1,1,0]};
plotLabelStyle = {FontFamily ->"Times",14,Plain, RGBColor[0.35,0.35,0.35],Background->RGBColor[1,1,1,0]};

(* Functions, Parameters and Controls *)
flist = {   (* NOTE: When adding another function, also add appropriate part to the fChooser! *)
{-x^2-y^2,{-4, 4},{-4,4},{-20,0}},
{Exp[x^2*y^2],{-1, 1},{-1,1},{1,2}},
{x^4+y^4-4 x y + 1,{-1.8, 1.8},{-1.8,1.8},{-1.5,2}},
{10x^2 y - 5 x^2 -4 y ^2 -x^4 -2 y^4,{-3,3},{-2,3},{-20,12}},
{2x^2+y^2,{-2,2},{-2,2},{0,10}}
};

numberOfLevelCurves =8;

f[x_,y_]:=flist[[1]][[1]]
xa = flist[[1]][[2]][[1]];
xb = flist[[1]][[2]][[2]];
ya= flist[[1]][[3]][[1]];
yb= flist[[1]][[3]][[2]];
za=flist[[1]][[4]][[1]];
zb=flist[[1]][[4]][[2]];
delta ={0,0};
maxDeltaX = Abs[xb-xa]/2;
maxDeltaY =Abs[yb-ya]/2;

fChooser =Labeled[ ActionMenu[Style["f(x,y) = ",textStyle],
{
ToString[TraditionalForm[flist[[1]][[1]]]]:>(
f[x_,y_]:=flist[[1]][[1]];
xa = flist[[1]][[2]][[1]];
xb = flist[[1]][[2]][[2]];
ya= flist[[1]][[3]][[1]];
yb= flist[[1]][[3]][[2]];
za=flist[[1]][[4]][[1]];
zb=flist[[1]][[4]][[2]];
maxDeltaX = Abs[xb-xa]/2;
maxDeltaY =Abs[yb-ya]/2;),
ToString[TraditionalForm[flist[[2]][[1]]]]:>(
f[x_,y_]:=flist[[2]][[1]];
xa = flist[[2]][[2]][[1]];
xb = flist[[2]][[2]][[2]];
ya= flist[[2]][[3]][[1]];
yb= flist[[2]][[3]][[2]];
za=flist[[2]][[4]][[1]];
zb=flist[[2]][[4]][[2]];
maxDeltaX = Abs[xb-xa]/2;
maxDeltaY =Abs[yb-ya]/2;),
ToString[TraditionalForm[flist[[3]][[1]]]]:>(
f[x_,y_]:=flist[[3]][[1]];
xa = flist[[3]][[2]][[1]];
xb = flist[[3]][[2]][[2]];
ya= flist[[3]][[3]][[1]];
yb= flist[[3]][[3]][[2]];
za=flist[[3]][[4]][[1]];
zb=flist[[3]][[4]][[2]];
maxDeltaX = Abs[xb-xa]/2;
maxDeltaY =Abs[yb-ya]/2;),
ToString[TraditionalForm[flist[[4]][[1]]]]:>(
f[x_,y_]:=flist[[4]][[1]];
xa = flist[[4]][[2]][[1]];
xb = flist[[4]][[2]][[2]];
ya= flist[[4]][[3]][[1]];
yb= flist[[4]][[3]][[2]];
za=flist[[4]][[4]][[1]];
zb=flist[[4]][[4]][[2]];
maxDeltaX = Abs[xb-xa]/2;
maxDeltaY =Abs[yb-ya]/2;),
ToString[TraditionalForm[flist[[5]][[1]]]]:>(
f[x_,y_]:=flist[[5]][[1]];
xa = flist[[5]][[2]][[1]];
xb = flist[[5]][[2]][[2]];
ya= flist[[5]][[3]][[1]];
yb= flist[[5]][[3]][[2]];
za=flist[[5]][[4]][[1]];
zb=flist[[5]][[4]][[2]];
maxDeltaX = Abs[xb-xa]/2;
maxDeltaY =Abs[yb-ya]/2;)
}
],
Style["Function: ",textStyle],Left];

shifter2D = Labeled[
Dynamic[Slider2D[
Dynamic[delta],{{-maxDeltaX,-maxDeltaY},{maxDeltaX,maxDeltaY}}
]],Column[{
Style["Shift displayed domain by",textStyle],
Style["(Δx,Δy) = ("<>ToString[TraditionalForm[Dynamic[delta[[1]]]]]<>","<>ToString[TraditionalForm[Dynamic[delta[[2]]]]]<>")",textStyle],
Style["from origin:",textStyle]
}]
,Left];
numberOfLevelCurvesChooser = Labeled[SetterBar[Dynamic[numberOfLevelCurves],{1,2,3,4,5,6,8,10,12,15,20,30,50,100}],Style["Number Of Level Curves: ",textStyle],Left];

(* Plots *)
surfacePlot=Dynamic[Plot3D[f[x,y],{x,xa+delta[[1]],xb+delta[[1]]},{y,ya+delta[[2]],yb+delta[[2]]},AxesLabel->{x,y},ImageSize->{400,400},ClippingStyle->None,MeshFunctions->{#3&},Mesh->numberOfLevelCurves,PlotLabel->Style["\n"<>"f(x,y) = "<>ToString[TraditionalForm[f[x,y]]]<>" (Surface Plot)\n",plotLabelStyle],Background->RGBColor[1,1,1],PlotRange->{Full,Full,{za,zb}}]];contourPlot = Dynamic[ContourPlot[f[x,y],{x,xa+delta[[1]],xb+delta[[1]]},{y,ya+delta[[2]],yb+delta[[2]]},AxesLabel->{x,y},ImageSize->{400,400},Contours->numberOfLevelCurves,ContourLabels->Automatic,ContourShading->None,ClippingStyle->None,PlotLabel->Style["\n"<>"f(x,y) = "<>ToString[TraditionalForm[f[x,y]]]<>" (Level Curves)\n",plotLabelStyle],PlotRange->{Full,Full,{za,zb}},Background->RGBColor[1,1,1]]];

Manipulate[
TabView[
{Style["Level Curves",titleStyle]->
Column[{
"",
Row[{
"   ",
Column[{
fChooser,
"    ",
numberOfLevelCurvesChooser
}],
"    ",
shifter2D,
"    "
}],
Row[{
"  "
}],
"   ",
Row[{
"  ",
Column[{
surfacePlot,
Style["Rotate and zoom plot",textStyle,10]
},Center]
"  ",
Column[{
contourPlot,
Style["Point with mouse on level curve to display z value",textStyle,10]
}, Center]
"  ",
"  "
}]
}]
},Background->RGBColor[0.85,0.85,0.85]]
,SaveDefinitions->True,AppearanceElements->None,Paneled->False]

© 2009 Projekt LEMUREN, Lernen Multimedial, Departement Mathematik, ETH Zürich