You are on page 1of 2

Making a "volcanic landscape"

Polynomial functions of two variables may be neat for algebra-- but they do not occur
frequently in applications, and they are useless for interesting plots. BOUNDED rational
functions like f(x,y)=(-x/(1+x^2+y^2)), and functions defined in terms of trig functions
like f(x,y)=sin(x)*cos(y) are much btter suited for explorations.
A really neat alternative for fun pictures (that we use later when differentiating etc, and that
actually becomes more important in applications, including "neural networks") is illustrated
here.
Start with a simple "bump":
> with(plots);
# plotsetup(plotdevice=window);
setoptions3d(shading=ZHUE,style=patchcontour);

> volcano:=exp(-x^2-y^2);
plot3d((volcano),x=-3..3,y=-3..3);

Next translate and scale the bump:


> miningpit:=-.6*exp(-(x-1)^2-(y+.5)^2);
plot3d((miningpit),x=-3..3,y=-3..3);

Combine the crater and the volcano by adding their formula:

> arizona:=volcano+miningpit;
plot3d((arizona),x=-3..3,y=-3..3);

To somewhat automate the creation of more fun landscapes one may proceed as follows:

> f:=(a,b,c)->c*exp(-(x-a)^2-(y-b)^2);

> moon:=f(0,0,-3)+f(2,2,2)+f(-2,-2,2)+f(-1,2,3)+f(1,-2,2)+f(2,0,
2);

> printf("%a", moon);


-3*exp(-x^2-y^2)+2*exp(-(x-2)^2-(y-2)^2)+2*exp(-(x+2)^2-(y+2)^2)+3*exp(-
(x+1)^2-(y-2)^2)+2*exp(-(x-1)^2-(y+2)^2)+2*exp(-(x-2)^2-y^2)
> plot3d(moon,x=-3..3,y=-3..3,style=patchcontour,grid=[30,30]);
Now with almost ten times as many points -- you decide whether you are willing to wait to get
really
pretty graphics, or whether in a class like ours the rough images are good enough to learn the
general
concepts and principles.
> plot3d(moon,x=-3..3,y=-3..3,style=patchcontour,grid=[45,45],
contours=25);

> ?plot3d,options
For fun, we conclude with an animation of successive cross-sections parallel to the x-axis.
Here "moon" is an expression in x and y, and thus we use "subs" to fix y at specific values for b.
> display([seq(plot(subs(y=b/2,moon),x=-3..3),b=-6..6)],
thickness=2,insequence=true);

You might also like