comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Check numerical derivatives
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Check numerical derivatives [message #94529 is a reply to message #94527] Tue, 27 June 2017 07:52 Go to previous messageGo to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
Yes, that looks correct to compute left-sided difference derivatives. But a few comments:

1. You don't need the xc,yc vectors, just use the function directly

F_x = F[1:nx-1,*]-F[0:nx-2,*]

2. You do not compute derivatives for the first column. Be careful because your derivative array has one less column than the original function.

3. Unless you need high compute speed, I would instead use the DERIV() function to obtain centered derivatives, with special treatment of the endpoints

F_x = fltarr(nx,ny)
for i=0,nx-1 do F_x[0,i] = $
DERIV(F[*,i])

--Wayne

On Tuesday, June 27, 2017 at 6:30:59 AM UTC-4, geo...@gmail.com wrote:
> Hi there,
>
> I wanted to calculate numerical derivatives of a function. I would like to check if the following are correct.
>
> Consider the function F in R^2.
> F is a 2D image.
> I did the following:
> dims = size(F, /dimensions)
> nx = dims[0]
> ny = dims[1]
> xc = findgen(nx)
> yc = findgen(ny)
>
> Derivative with respect to x:
> F_x = F[xc[1:nx-1],*]-F[xc[0:nx-2],*] ;first order deriv
> F_xx = F_x[xc[1:nx-1],*]-F[xc[0:nx-2],*] ;second order deriv
> F_y = F[*,yc[1:ny-1]] - F[*,yc[0:ny-2]]
> F_xy = F_x[*,yc[1:ny-1]] - F_x[*,yc[0:ny-2]]
>
> Then I wanted to differentiate F_xy with respect to x. I did the following:
> F_xxy = F_xy[xind[1:nx-1],*] - F_xy[xind[0:nx-2],*]
>
> Are the above correct?
>
> Thanks.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Removing specific elements in an array
Next Topic: 2D histogram color plot

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:13:31 PDT 2025

Total time taken to generate the page: 0.00444 seconds