You are on page 1of 1

Chapter 8: Base modules 160

// Major contours
real[] Cvals=uniform(range.min,range.max,Divs);
draw(contour(f,a,b,Cvals,N,operator --),Tickpen+squarecap+beveljoin);

// Minor contours (if divs > 1)


real[] cvals;
for(int i=0; i < Cvals.length-1; ++i)
cvals.append(uniform(Cvals[i],Cvals[i+1],divs)[1:divs]);
draw(contour(f,a,b,cvals,N,operator --),tickpen);

xaxis("$x$",BottomTop,LeftTicks,above=true);
yaxis("$y$",LeftRight,RightTicks,above=true);

palette("$f(x,y)$",range,point(SE)+(0.5,0),point(NE)+(1,0),Right,Palette,
PaletteTicks("$%+#0.1f$",N=Divs,n=divs,Tickpen,tickpen));

+1.0
6
+0.8
5 +0.6
+0.4
4
+0.2

f (x, y)
y 0.0
3
−0.2
2 −0.4
−0.6
1
−0.8
0 −1.0
0 1 2 3 4 5 6
x

import graph;
import palette;
import contour;

size(10cm,10cm);

pair a=(0,0);
pair b=(2pi,2pi);

real f(real x, real y) {return cos(x)*sin(y);}

int N=200;

You might also like