Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
I have a 2d function z=f(x,y). I need to calculate the partial derivatives df/dx and df/dy for all the grid points. Is there a routine for this somewhere? Thanks-Peter Brooker
In article <3mmmpv$g0l@agate.berkeley.edu>, korpela@albert.ssl.berkeley.edu (Eric J. Korpela) wrote: > In article <D6xz1s.ADE@ireq.hydro.qc.ca>, > <brooker@toka.ireq-ccfm.hydro.qc.ca> wrote: >> I have a 2d function z=f(x,y). I need to calculate >> the partial derivatives df/dx and df/dy for all the >> grid points. Is there a routine for this somewhere? > > delta=some_small_number ;compared to the grid spacing > dz_dx=(f(x+delta,y)-f(x-delta,y))/(2.0*delta) > dz_dy=(f(x,y+delta)-f(x,y-delta))/(2.0*delta) Perhaps he wanted: z = FLTARR(nx,ny) dzdx = FLTARR(nx,ny) dzdy = FLTARR(nx,ny) FOR j = 0, ny-1 DO $ dzdx(*,j) = (ROTATE(z(*,j),-1) - ROTATE(z(*,j),1))/(2.0*dx) FOR j = 1, ny-2 DO $ dzdy(*,j) = (z(*,j+1) - z(*,j-1))/(2.0*dy) ...then whatever you want to do for the normal derivatives on the boundaries... You could do this without the ROTATE's by looping over i for dzdx, but then you would access memory with a large stride. I think this will use the cache much more efficiently on most workstations. Regards, Ken Bowman -- Dr. Kenneth P. Bowman 409-862-4060 Associate Professor 409-862-4132 fax Department of Meteorology bowman@csrp.tamu.edu Texas A&M University PP-Glider College Station, TX 77843-3150
In article <D6xz1s.ADE@ireq.hydro.qc.ca>, <brooker@toka.ireq-ccfm.hydro.qc.ca> wrote: > I have a 2d function z=f(x,y). I need to calculate > the partial derivatives df/dx and df/dy for all the > grid points. Is there a routine for this somewhere? > Provided free of charge........ (Unless Unisys has patented it :) ) Assuming x and y are arrays..... delta=some_small_number ;compared to the grid spacing dz_dx=(f(x+delta,y)-f(x-delta,y))/(2.0*delta) dz_dy=(f(x,y+delta)-f(x,y-delta))/(2.0*delta) Eric -- Eric Korpela | A day without meetings is like korpela@ssl.berkeley.edu | work. Click here for more info.