Path: news.mathworks.com!not-for-mail
From: "mahshid " <mahshid770@yahoo.com>
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$1@fred.mathworks.com>
References: <i9o4nk$kp9$1@fred.mathworks.com> <i9ob23$pcb$1@fred.mathworks.com>
Reply-To: "mahshid " <mahshid770@yahoo.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1287632283 423 172.30.248.37 (21 Oct 2010 03:38:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 21 Oct 2010 03:38:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1144111
Xref: news.mathworks.com 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.

Regards,
Mahshid
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invlid> wrote in message <i9ob23$pcb$1@fred.mathworks.com>...
> "mahshid " <mahshid770@yahoo.com> wrote in message <i9o4nk$kp9$1@fred.mathworks.com>...
> > 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