Hi Søren,
I would like to contribute with the divergence function. This function
is used to compute divergence of vector field and is not included in
Octave's distribution. So, could you please give a suggestion on where
to locate the file within the repository?
Thanks a lot.
Regards,
Javier
## Copyright (C) 2009 Javier Enciso <[email protected]>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see
## <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Function file} {} divergence (@var{X}, @var{Y}, @var{Z},
@var{U}, @var{V}, @var{W})
## @deftypefnx {Function file} {} divergence (@var{U}, @var{V}, @var{W})
## @deftypefnx {Function file} {} divergence (@var{X}, @var{Y}, @var{U},
@var{V})
## @deftypefnx {Function file} {} divergence (@var{U}, @var{V})
## Compute divergence of vector field.
##
## @code{divergence(X, Y, Z, U, V, W)} computes the divergence of a 3-D vector
field
## @var{U}, @var{V}, @var{W} at the points @var{X}, @var{Y}, @var{Z}.
Coordinate points
## must preserve the given order and define a 3-dimensional grid.
##
## If @var{X}, @var{Y}, and @var{Z} are omitted, @code{divergence(U,V,W)}
assumes
## that the coordinates are given by the expression @code{[X Y Z] =
meshgrid(1:n,1:m,1:p)}
## where @code{[m,n,p] = size(U)}.
##
## @code{divergence(X, Y, U, V)} computes the divergence of a 2-D vector field
@var{U},
## @var{V} at the points @var{X}, @var{Y}. Coordinate points must preserve the
given order
## and define a 2-dimensional grid.
##
## If @var{X} and @var{Y} are omitted, @code{divergence(U,V)} assumes that the
## coordinate points @var{X} and @var{Y} are given by the expression @code{[X
Y] =
## meshgrid(1:n,1:m)} where @code{[m,n] = size(U)}.
## @end deftypefn
function [div] = divergence(varargin)
if nargin < 2
print_usage();
return
elseif nargin == 2
u = varargin{1};
v = varargin{2};
if uvcheck(u,v) == 1
[du dump] = gradient(u);
[dump dv] = gradient(v);
div = du + dv;
return
end
elseif nargin == 3
u = varargin{1};
v = varargin{2};
w = varargin{3};
if uvwcheck(u,v,w) == 1
[du dump dump] = gradient(u);
[dump dv dump] = gradient(v);
[dump dump dw] = gradient(w);
div = du + dv + dw;
return
end
elseif nargin == 4
x = varargin{1};
y = varargin{2};
u = varargin{3};
v = varargin{4};
if xyuvcheck(x,y,u,v) == 1
[du dump] = gradient(u);
[dump dv] = gradient(v);
[dx dump] = gradient(x);
[dump dy] = gradient(y);
div = du./dx + dv./dy;
return
end
elseif nargin == 6
x = varargin{1};
y = varargin{2};
z = varargin{3};
u = varargin{4};
v = varargin{5};
w = varargin{6};
if xyzuvwcheck(x,y,z,u,v,w) == 1
[du dump dump] = gradient(u);
[dump dv dump] = gradient(v);
[dump dump dw] = gradient(w);
[dx dump dump] = gradient(x);
[dump dy dump] = gradient(y);
[dump dump dz] = gradient(z);
div = du./dx + dv./dy + dw./dz;
return
end
else
print_usage();
return
end
function [msg] = uvcheck(u, v)
d = zeros(1,2);
d(1) = ndims(u);
d(2) = ndims(v);
if find(d(1,:) ~= 2)
error('Matrices must have 2 dimensions');
end
d = zeros(2);
d(1,:) = size(u);
d(2,:) = size(v);
if find(d(1,:) == d(2,:) == 0)
error('Size of matrices must be equal');
end
msg = 1;
function [msg] = xyuvcheck(x, y, u, v)
d = zeros(1,4);
d(1) = ndims(x);
d(2) = ndims(y);
d(3) = ndims(u);
d(4) = ndims(v);
if find(d(1,:) ~= 2)
error('Matrices must have 2 dimensions');
end
d = zeros(4,2);
d(1,:) = size(x);
d(2,:) = size(y);
d(3,:) = size(u);
d(4,:) = size(v);
for m = 1:3
if find(d(m,:) == d(m+1,:) == 0)
error('Size of matrices must be equal');
end
end
msg = 1;
function [msg] = uvwcheck(u, v, w)
d = zeros(1, 3);
d(1) = ndims(u);
d(2) = ndims(v);
d(3) = ndims(w);
if find(d(1,:) ~= 3)
error('Matrices must have 3 dimensions');
end
d = zeros(3);
d(1,:) = size(u);
d(2,:) = size(v);
d(3,:) = size(w);
for m = 1:2
if find(d(m,:) == d(m+1,:) == 0)
error('Size of matrices must be equal');
end
end
msg = 1;
function [msg] = xyzuvwcheck(x, y, z, u, v, w)
d = zeros(1,6);
d(1) = ndims(x);
d(2) = ndims(y);
d(3) = ndims(z);
d(4) = ndims(u);
d(5) = ndims(v);
d(6) = ndims(w);
if find(d(1,:) ~= 3)
error('Matrices must have 3 dimensions');
end
d = zeros(6,3);
d(1,:) = size(x);
d(2,:) = size(y);
d(3,:) = size(z);
d(4,:) = size(u);
d(5,:) = size(v);
d(6,:) = size(w);
for m = 1:5
if find(d(m,:) == d(m+1,:) == 0)
error('Size of matrices must be equal');
end
end
msg = 1;------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev