partial derivatives of f(x,y) [message #3968] |
Wed, 12 April 1995 00:00  |
brooker
Messages: 12 Registered: March 1994
|
Junior Member |
|
|
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
|
|
|
Re: partial derivatives of f(x,y) [message #4050 is a reply to message #3968] |
Fri, 14 April 1995 00:00  |
bowman
Messages: 121 Registered: September 1991
|
Senior Member |
|
|
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
|
|
|
|