next up previous contents
Next: Surface plots Up: An Introduction to IDL Previous: A couple of exercises   Contents

Lecture 3: Graphics (for functions of two variables)

We've seen simple x-y plots, we'll now look at plots of functions of two variables. e.g. the height of the ground above sea level as a function of distance East and distance North.

pro example2d
nx=21                           ; Number of points in x direction
ny=31                           ; Number of points in y direction
xmin=-2                         ; x axis goes from xmin ... 
xmax=2                          ; ... to xmax
ymin=-2                         ; y axis goes from ymin ... 
ymax=2                          ; ... to ymax

; make 1-d arrays containing x axis and y axis values
x=xmin + findgen(nx)*(xmax-xmin)/(nx-1);distance east (m)
y=ymin + findgen(ny)*(ymax-ymin)/(ny-1);distance north (m)
; z is a 2-d array which will contain the data values  
z=fltarr(nx,ny)

; x2d and y2d are arrays the same size as z. 
; This is done so that we can calculate z without using nested for loops.
x2d=x#(y*0.+1)     ;2D array of x values at each point
y2d=(x*0.+1)#y     ;2D array of y values at each point

; calculate z. (Height above mean sea level (m))
z=exp(-(x2d^2 +y2d^2)) + 0.6*exp(-((x2d+1.8)^2 +(y2d) ^2))

stop
end

Run it (or cut and paste to the IDL prompt):

example2d



Subsections

lecjm 2008-11-06