On Sat, Mar 21, 2009 at 08:41:50PM +0100, Søren Hauberg wrote: > lør, 21 03 2009 kl. 20:29 +0100, skrev Carlo de Falco: > > either this is a bug or it changed in more recent versions of matlab? > > Either way, NaN is a really weird return value. How about changing the > function into > > function y = heaviside (x, zero_value = 0.5) > if (nargin < 1) > print_usage (); > endif > > y = cast (x > 0, class (x)); > y (x == 0) = zero_value; > endfunction
> > ? Then it'll behave sensible by default, and people that really want > NaN's can still get it. I agree. I think this is most sensible. It is consistent with the wikipedia page: http://en.wikipedia.org/wiki/Heavyside_function Also, I would suggest the function require that x be real. Heaviside function is not defined for non-numeric or for complex-number arguments; (if Z is complex, the expression Z>0 makes no sense). function y = heaviside (x, zero_value = 0.5) if (nargin < 1) print_usage (); endif if ( ! isreal(x) || ! isreal(zero_value) ) error( "heaviside: args must be real") endif y = x > 0; y (x == 0) = zero_value; endfunction BTW, according to www.mathworks documentation, heaviside(0) in matlab now returns 0.5. -- Peter ------------------------------------------------------------------------------ Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are powering Web 2.0 with engaging, cross-platform capabilities. Quickly and easily build your RIAs with Flex Builder, the Eclipse(TM)based development software that enables intelligent coding and step-through debugging. Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com _______________________________________________ Octave-dev mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/octave-dev
