Path: news.mathworks.com!not-for-mail From: "Adrian " <adrianb_remove_this@uga.edu> Newsgroups: comp.soft-sys.matlab Subject: Problems with Logs and the gradient function Date: Thu, 12 Aug 2010 21:14:05 +0000 (UTC) Organization: University of Georgia Lines: 37 Message-ID: <i41o6t$1l3$1@fred.mathworks.com> Reply-To: "Adrian " <adrianb_remove_this@uga.edu> 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 1281647645 1699 172.30.248.37 (12 Aug 2010 21:14:05 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Thu, 12 Aug 2010 21:14:05 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2119530 Xref: news.mathworks.com comp.soft-sys.matlab:661588 I am trying to understand the gradient function in Matlab. As I understand it, gradient(y) for y a vector, will calculate the gradient of y assuming a unit interval between the points. In other words, it will calculate dy/dx assuming dx=1 for all points in the series. This works as expected if I have x = 1:20; y = x.^2; dydx = 2*x; disp([dydx; gradient(y)]); in which case dydx and gradient(y) produce the same vales (except at the end points which is to be expected). Now let's take the same function but have the x values geometrically spaced n = 1:10; x = 2.^(n-1); y = x.^2; If I use the gradient function, it will still assume a unit spacing of x between the data points. My question is: why isn't gradient(y) = dy/dlog2(x)? log2(x) is equally spaced with unit interval but the gradient function is producting something different. In this case, dy/dlog2(x) = 2*log(2)*x.*x but this is not equal to the values produced by gradient(y). However, the ratio between the two is constant (except at the endpoints) (dy/dlog2(x))./gradient(y) = 0.73936 I'm obviously missing something somewhere, can someone help me out here? Thanks, Adrian