<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>k-Wave User Forum &#187; Topic: Evaluating gradient in &#039;non-uniform&#039; grid</title>
		<link>http://www.k-wave.org/forum/topic/evaluating-gradient-in-non-uniform-grid</link>
		<description>Support for the k-Wave MATLAB toolbox</description>
		<language>en-US</language>
		<pubDate>Wed, 13 May 2026 03:45:38 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.k-wave.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.k-wave.org/forum/rss/topic/evaluating-gradient-in-non-uniform-grid" rel="self" type="application/rss+xml" />

		<item>
			<title>Bradley Treeby on "Evaluating gradient in &#039;non-uniform&#039; grid"</title>
			<link>http://www.k-wave.org/forum/topic/evaluating-gradient-in-non-uniform-grid#post-3664</link>
			<pubDate>Mon, 20 May 2013 14:59:51 +0000</pubDate>
			<dc:creator>Bradley Treeby</dc:creator>
			<guid isPermaLink="false">3664@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi Luca,&#60;/p&#62;
&#60;p&#62;The k-Wave functions &#60;code&#62;gradientFD&#60;/code&#62; and &#60;code&#62;getFDMatrix&#60;/code&#62; require the grid points to be evenly spaced. If your grid points are not evenly spaced, you will have to generate the finite difference coefficients at each position manually. This is not difficult, just fiddly. See for example: &#60;/p&#62;
&#60;p&#62;B. Fornberg, “Generation of finite difference formulas on arbitrarily spaced grids,” Math. Comput, vol. 51, no. 184, pp. 699–706, 1988. &#60;/p&#62;
&#60;p&#62;You could also see if there is anything on the MATLAB file exchange, e.g., &#60;a href=&#34;http://www.mathworks.co.uk/matlabcentral/fileexchange/8016-1-d-unstructured-finite-differences&#34;&#62;here&#60;/a&#62;.&#60;/p&#62;
&#60;p&#62;Brad.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>lucamagher on "Evaluating gradient in &#039;non-uniform&#039; grid"</title>
			<link>http://www.k-wave.org/forum/topic/evaluating-gradient-in-non-uniform-grid#post-3663</link>
			<pubDate>Mon, 20 May 2013 14:39:11 +0000</pubDate>
			<dc:creator>lucamagher</dc:creator>
			<guid isPermaLink="false">3663@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Thank you very much Brad.&#60;br /&#62;
How can I handle non-evenly spaced grid points?&#60;/p&#62;
&#60;p&#62;My actual problem is that dx and dy are not constant, as in the preceding example.&#60;br /&#62;
So, my problem is akin to this:&#60;/p&#62;
&#60;p&#62;dx = sort(rand(100,1));&#60;br /&#62;
dy = sort(rand(50,1));&#60;/p&#62;
&#60;p&#62;x = 10*dx;&#60;br /&#62;
y = 5*dy;&#60;/p&#62;
&#60;p&#62;[X,Y] = meshgrid(x,y);&#60;br /&#62;
f = cos(2*pi*X).*Y;&#60;/p&#62;
&#60;p&#62;dfx = gradientFD(f,dx,2);&#60;br /&#62;
dfy = gradientFD(f,dy,1);&#60;/p&#62;
&#60;p&#62;subplot(2,1,1)&#60;br /&#62;
pcolor(X,Y,dfx), shading interp&#60;br /&#62;
subplot(2,1,2)&#60;br /&#62;
pcolor(X,Y,dfy), shading interp&#60;/p&#62;
&#60;p&#62;Where am I doing wrong here?&#60;br /&#62;
Thank you very much for your assistance. &#60;/p&#62;
&#60;p&#62;Luca
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Bradley Treeby on "Evaluating gradient in &#039;non-uniform&#039; grid"</title>
			<link>http://www.k-wave.org/forum/topic/evaluating-gradient-in-non-uniform-grid#post-3661</link>
			<pubDate>Mon, 20 May 2013 13:59:09 +0000</pubDate>
			<dc:creator>Bradley Treeby</dc:creator>
			<guid isPermaLink="false">3661@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi lucamagher,&#60;/p&#62;
&#60;p&#62;The second input to the &#60;code&#62;gradientFD&#60;/code&#62; function should be the grid-point spacing, rather than an array of the grid coordinates, i.e., &#60;/p&#62;
&#60;pre&#62;&#60;code&#62;dfx = gradientFD(f, dx, 2);
dfy = gradientFD(f, dy, 1);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;where &#60;code&#62;dx&#60;/code&#62; and &#60;code&#62;dy&#60;/code&#62; are 0.01 in your example.&#60;/p&#62;
&#60;p&#62;Brad.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>lucamagher on "Evaluating gradient in &#039;non-uniform&#039; grid"</title>
			<link>http://www.k-wave.org/forum/topic/evaluating-gradient-in-non-uniform-grid#post-3660</link>
			<pubDate>Mon, 20 May 2013 12:51:18 +0000</pubDate>
			<dc:creator>lucamagher</dc:creator>
			<guid isPermaLink="false">3660@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi guys&#60;br /&#62;
I am sure I am being stupid with this question. My apologies in advance. &#60;/p&#62;
&#60;p&#62;I have an unequal spacing grid of points, say, size(grid) = [100 200].&#60;br /&#62;
I want to evaluate the gradient of a function f(grid) along both dimensions of the grid.&#60;br /&#62;
How can I do this?&#60;/p&#62;
&#60;p&#62;Just to play around with function gradientFD, I coded :&#60;br /&#62;
x = 0:0.01:10;&#60;br /&#62;
y = 0:0.01:5;&#60;/p&#62;
&#60;p&#62;[X,Y] = meshgrid(x,y);&#60;br /&#62;
f = cos(2*pi*X).*Y;&#60;/p&#62;
&#60;p&#62;dfx = gradientFD(f,x,2);&#60;br /&#62;
dfy = gradientFD(f,y,1);&#60;/p&#62;
&#60;p&#62;dfx is evaluated correctly, whereas dfy is not.&#60;br /&#62;
What is wrong with my understanding of gradientFD function ?&#60;br /&#62;
Thanks much
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
