"Yi Cao" <firstname.lastname@example.org> wrote in message <email@example.com>... > "Md. Shahriar Karim" <firstname.lastname@example.org> wrote in message <email@example.com>... > > Hi, > > > > I am given a vector say A= [.....................] that describe a function say f(x). Now, I have to calculate the derivetive d(A)/d(x). x = 1: N and is equally spaced with any equal width (0.1 or 0.5 or 1 or anything). I was using both > > diff (A) > > gradient (A) > > > > however, the derivative value I get using diff and gradient result in different output when cascaded to in next calculation. Becasue, my last calculation is highly sensitive of derivative (d(A)/d(x)) value as the derivative value I am using to plot the cramer-rao bound for an estimator. > > > > Could you please say which process amongst diff (A) and gradient (A) is more accurate in finding the derivative of a vector? > > > > Is there anyother way that can be used to obtain the same with even greater accuracy? Thanks, > > > > > > Karim > > Neither diff nor gradient is reliable in this application. You can use either finite difference (FD) or automatic differentiation (AD) to calculate dA/dx. There are some tools in File Exchange available for both FD and AD. For example: > > For FD, my Complex Step Jacobian tool will be useful, http://www.mathworks.com/matlabcentral/fileexchange/18176 > To use this tool, if your function has transpose ('), you have to convert it to (.'). > > For AD, the recent submission may be useful: > http://www.mathworks.com/matlabcentral/fileexchange/26807 > > HTH > Yi
Hi, if i use the adiff function to calculate the derivative, how will we use this? For example, vecotr A = [1......N] is describing the function but we do NOT know what kind of equation does it have. All we know is that the function has some value on some different points (X = 1,2,... ....say 30)).
How would the adiff and adiffget would fit in this case? I saw that to use adiffget we have got to have a existing equation that governs the relation between X (points where derivative to be calculation) and function (X).