Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Defining x and y in 2D matrix
Date: Mon, 21 May 2012 21:54:06 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 14
Message-ID: <jpedhu$mri$1@newscl01ah.mathworks.com>
References: <jpe7b9$phh$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1337637246 23410 172.30.248.37 (21 May 2012 21:54:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 21 May 2012 21:54:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:768535

"Saud Alkhaldi" wrote in message <jpe7b9$phh$1@newscl01ah.mathworks.com>...
> I have a question that's asking me to ise the 4 point central difference to calculate the partial derivatives of the function z=f(x,y). However, I'm only given a set of data in a 100x101 matrix. How can I define my x and y vectors so I can proceed with finding the derivatives.
- - - - - - - - - -
  If you're being asked to use the four point central difference formula to calculate derivatives in a 100 x 101 matrix of z = f(x,y) values, the presumption I would make is that the x and y values correspond linearly to the indices of the matrix.  In other words the x-interval between two horizontally adjacent matrix values z(ix,iy) and z(ix+1,iy) is understood to be some constant value h and between two vertically adjacent values z(ix,iy) and z(ix,iy+1) is a constant k in y-difference.

  That means at each point z(ix,iy) the approximate first partial derivative with respect to x will be given by the four-point central difference using z(ix-2,iy), z(ix-1,iy), z(ix+1,iy) and z(ix+2,iy), and doesn't involve z(ix,iy).  It is up to you to decide what h, the x-difference, is to be for the formula.  That formula would be:

 dz/dx(ix,iy) = (z(ix-2,iy)-8*z(ix-1,iy)+8*z(ix+1,iy)-z(ix+2,iy))/(12*h)

A similar statement holds for the first partial with respect to y using k and differences in iy.

  You will note that you cannot apply this formula at the four edges of your matrix since for example you have no values of z for x-indices 0 and -1 or for 101 and 102.  You will have to decide to either derive the appropriate third order approximation at the edges or use a cruder difference method there.

Roger Stafford