e-Statistics > 4470-5470 Probability and Statistics I ## Drawing bivariate densities

Maxima has a powerful graphics function draw3d. In order to use it we must first load the "draw" package.
--> load(draw)

In a 3D plot a function is described in the format with the plotting range and .

In Maxima a function can be defined and works as a macro definition. For example, we can define by setting it with the symbol ":="
--> Q(x,y) := ((x - m)^2/s^2 + (y - m)^2/s^2 - 2*r*(x - m)*(y - m)/(s*s))

Also, we have to give the parameters as follows:
--> m: [1,2]
--> s: [2,1]
--> r: 0.3

Then we can define the bivariate density function by
--> f(x,y) := exp(-Q(x,y)/2)/(2*%pi*s*s*sqrt(1-r^2))


We can draw a surface when "enhanced3d=true" is specified.

--> draw3d(enhanced3d=true,
explicit(f(x,y),x,-2,4,y,-2,4),
user_preamble="unset colorbox")

We can obtain contour curves when "contour=map" is specified.
--> draw3d(color=red, contour=map, contour_levels=15,
explicit(f(x,y),x,-2,4,y,-2,4),
user_preamble="unset clabel")

We can draw both the surface and the contour curves when "contour=both" is specified.
--> draw3d(surface_hide=true, contour=both, contour_levels=15,
explicit(f(x,y),x,-2,4,y,-2,4))


The option "contour_levels" can be chosen from the following styles.

• "contour_levels=n" n is set to the number of contour lines drawn at equal intervals.
• "contour_levels=[a,s,b]" The contour curves are plotted from the lowest value a to the highest value b in steps of the value s.
• "contour_levels={c1,c2,...,cn}" The contour curves are plotted at the values c1, c2,...,cn.

The following wxm file contains the above code: