From: "mahshid " <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: gradient
Date: Thu, 21 Oct 2010 03:38:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 23
Message-ID: <i9ocir$d7$>
References: <i9o4nk$kp9$> <i9ob23$pcb$>
Reply-To: "mahshid " <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1287632283 423 (21 Oct 2010 03:38:03 GMT)
NNTP-Posting-Date: Thu, 21 Oct 2010 03:38:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1144111
Xref: comp.soft-sys.matlab:680033

Tanx Roger,

You are right, now could u pls tell me how i can obtain these 2nd derivatives numerically?do i have to fit a curve before? for instanse i tried "differentiate" but i seems that a curvfitting must be done before.

"Roger Stafford" <> wrote in message <i9ob23$pcb$>...
> "mahshid " <> wrote in message <i9o4nk$kp9$>...
> > Hi there;
> > 
> > i need to obtain first and second derivative numerically in my code. can i use gradient in the following form:
> > [px,py] = gradient(qz,.25,.25);
> >  [pxx,pxy]=gradient(px,.25,.25);
> >  [pyx,pyy]=gradient(py,.25,.25);
> >  tnx
> - - - - - - - - - - -
>   Doing 'gradients' of 'gradients' may not result in an optimum approximation to second derivatives.  For example, with a single variable, if vector v = [v1,v2,v3,v4,v5], the gradient at the 2nd, 3rd, and 4th positions will be the central differences (v3-v1)/(2*h), (v4-v2)/(2*h), and (v5-v3)/(2*h).  If the gradient is taken again, this results in
>  ((v5-v3)/(2*h)-(v3-v1)/(2*h))/(2*h) = (v5-2*v3+v1)/(4*h^2)
> at the 3rd position.  While this may be adequate for some purposes it is probably not optimum.  The values v2 and v4 are not represented at all in this differencing of differences.  If one is going as far out as v1 and v5, there are better expressions involving all five v values for approximating the second derivative at this 3rd position.
> Roger Stafford