octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: divergence function


From: Jaroslav Hajek
Subject: Re: divergence function
Date: Tue, 29 Sep 2009 11:38:54 +0200

On Tue, Sep 29, 2009 at 11:16 AM, Javier Enciso <address@hidden> wrote:
> Hi All,
>
> I' not sure whether this email already reach you guys, I wasn't member of
> the mailing list, anyway I just resend it.
>
> I'm glad to contribute with the 'divergence' function. This function
> is used to compute divergence of vector field and is part of Matlab's
> core functions.
>
> In doubt, please feel free to contact me.
>
> Regards,
> Javier
>

Hello Javier,

I have a couple of suggestions:
1. Please don't use tabs (or 8 spaces) to indent the code; use two
spaces. This is done everywhere in Octave sources.

2. blocks like
>                        x = varargin {1};
>                        y = varargin {2};
>                        z = varargin {3};
>                        u = varargin {4};
>                        v = varargin {5};
>                        w = varargin {6};
can be abbreviated to

[x,y,z,u,v,w] = deal (varargin{1:6});

this improves readability. Consider doing it.

3. in check_dim, the for loops can be avoided:

function [] = check_dim (varargin)
  if (!size_equal (varargin{:})
    error ("Size of matrices must be equal");
  endif

  switch (nargin)
  case {2, 4}
    if (any (cellfun (@ndims, varargin) != 2))
      error ("Matrices must have 2 dimensions");
    endif
  case {3, 6}                   
    if (any (cellfun (@ndims, varargin) != 3))
      error ("Matrices must have 3 dimensions");
    endif
  endswitch
endfunction


no big concern about performance in this case, since nargin is small,
but it also seems to improve readability, at least to me...

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]