Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Numerical error in gradient().

Subject: Numerical error in gradient().

From: Cristiano Strieder

Date: 27 Sep, 2010 01:17:04

Message: 1 of 2

Hi,

what is the numerical error when using the function [FX,FY]=gradient(F)?

Subject: Numerical error in gradient().

From: Roger Stafford

Date: 27 Sep, 2010 04:34:04

Message: 2 of 2

"Cristiano Strieder" <cstrieder@gmail.com> wrote in message <i7oraf$qvh$1@fred.mathworks.com>...
> Hi,
>
> what is the numerical error when using the function [FX,FY]=gradient(F)?
- - - - - - - - -
  For points not on the edge of the matrix, with x-intervals all equal, and likewise for the y-intervals, the gradient function gives

 FX(i,j) = (F(i,j+1)-F(i,j-1))/(2*dx)
 FY(i,j) = (F(i+1,j)-F(i-1,j))/(2*dy)

This is a second order type of approximation. The mean value theorem of calculus states that the error between these approximations and the actual partial derivative values are, for FX, equal to dx^2/6 times the third partial derivative with respect to x of F at some point between F(i,j+1) and F(i,j-1) and analogously for FY. That means for a smooth function with reasonably-behaved third derivatives, the error is proportional to the square of the the size of the steps in each direction.

  However, for unequal intervals no attempt is made to alter the basic formula:

 FX(i,j) = (F(i,j+1)-F(i,j-1))/(X(j+1)-X(j-1))
 FY(i,j) = (F(i+1,j)-F(i-1,j))/(Y(j+1)-Y(j-1))

and this now only constitutes only a first order approximation and the error is directly proportional to the size of the steps but in a way that depends on the way the intervals vary in size. The more variation the more the possible error. Also for points on the edge a different formula is used and this also gives only first order accuracy.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us