source("http://macosa.dima.unige.it/r.R") # If I have not already loaded the library ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- S 19 Complex numbers. Matrices. Functions of two variables. Series # Graph of a function of two variables. Example: f: (x,y)-> sin(x)+cos(2y) # theta, phi e d indicate the position of the eye: the direction of the look # projected on the horizontal plane, its inclination relative to that plane and the # distance of the eye from the center of the box. # The following picture shows the meaning of theta and phi: # (see S11 too) # If I want change the margin size I can use MARG(0.2) (reduce it to 0.2 inch) or MARG( ) f = function(x,y) sin(x)+cos(2*y) # I choose the size of the domain and the amount of grid lines x = seq(-pi,pi, len=20); y = seq(-pi,pi, len=20) # I create the "table" that x and y values associate z values z = outer(x,y,f) MARG(0.2); persp(x,y,z,phi=60,theta=30,d=20,col="yellow",ticktype="detailed",cex.axis=0.8,cex.lab=0.8) # The range of z is chosen automatically. I can change it if I add in "persp" (e.g.) ,zlim=c(-4,4), [see # If I want no color, and reduce the distance the 2nd graph] MARG(0.2); persp(x,y,z,phi=60,theta=30,d=2,col=NULL,ticktype="detailed",cex.axis=0.8,cex.lab=0.8) dev.new() # If I want open a new window (to retain the last graph) # If I want to choose the size of the window I can use BF= ; HF= ; NW() instead # With "expand" I can apply an expansion to the z coordinates MARG(0.2); persp(x,y,z,phi=60,theta=30,d=20,col="cyan",ticktype="detailed",expand=0.5,cex.axis=0.8,cex.lab=0.8) # (I must introduce scale=FALSE if I want a monometric system) # without "ticktype": dev.new(); MARG(0.2); persp(x,y,z,phi=60,theta=30,d=20,col="green", expand=1.5,cex.axis=0.8,cex.lab=0.8)
# To have the chart without the box I add: ",box=FALSE". # I can add pictures (with trans3d and pmat), if I have # given a name to the graph (here, fig): x = y = seq(-pi,pi, len=20); z = outer(x,y,f) MARG(0.2) fig = persp(x,y,z,phi=45,theta=65,d=20,col=NULL,box=FALSE) lines (trans3d(x=c(-pi,pi),y=0,z=0,pmat=fig), col="red",lwd=2) lines (trans3d(y=c(-pi,pi),x=0,z=0,pmat=fig), col="red",lwd=2) lines (trans3d(z=c(-1,1),x=0,y=0, pmat=fig), col="red",lwd=2) # I add ,lty=3 or =2 if I want dashed axes |