Plotting z = f(x,y)

In this section:

The following code is extracted from program simdem22.f95 in the Simdem package, and it illustrates how easy it is to plot a surface defined as z = f(x,y), where x, y, and z are double precision arrays. The x and y values must be in the form of a rectangular grid.


!
! Define x and y
!
      nx = 20
      ny = 20
      x(1) = - one
      x(nx) = one
      delta = (x(nx) - x(1))/(dble(nx) - one)
      do i = 2, nx - 1
         x(i) = x(i - 1) + delta
      enddo
      y(1) = - one
      y(ny) = one
      delta = (y(ny) - y(1))/(dble(ny) - one)
      do j = 2, ny - 1
         y(j) = y(j - 1) + delta
      enddo
!
! Define z = f(x,y) and the ranges (xmin,xmax), (ymin,ymax)
!
      do j = 1, ny
         do i = 1, nx
            z(i,j) = x(i)**2 - y(j)**2
         enddo
      enddo
      xmax = x(nx)
      xmin = x(1)
      ymax = y(ny)
      ymin = y(1)
!
! Display the surface, contours, projection, skyscraper blocks, etc.
!
      call surd2s (isend, nmax, nx, ny, vector, xmax, xmin, ymax, ymin, z, unused)

The following plot is then displayed, and can be edited to add further features, printed, or archived as a graphics file. The contours can be suppressed, or plotted separately, and there are options to rotate, add labels, arrows, text, graphical objects, etc. In addition, the points defined by z = f(x,y) can be plotted as bars, or cylinders, when error bars can also be added.

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited