help-octave
[Top][All Lists]
Advanced

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

Re: Integration of function containing if-test


From: Francesco Potortì
Subject: Re: Integration of function containing if-test
Date: Fri, 06 Feb 2009 02:05:44 +0100

>I have a function nu(x) that is defined using an if-test. It has a 
>special value (0) at x = 0, and is defined in terms of an ordinary 
>function f(x) everywhere else. Therefore I have:
>
>function y = nu(x)
>       if (x == 0)
>               y = 0;
>       else
>               y = f(x);
>       endif
>endfunction
>
>When I pass it a 0 it returns a zero. But when I pass it a vector [0 1] 
>it doesn't work

If the function f works with vectors, then:

function y = nu(x)
  y = zeros (size (x));
  notzero = x(x != 0);
  y(notzero) = f (x(notzero));
endfunction

-- 
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: address@hidden
(entrance 20, 1st floor, room C71)     Web:   http://fly.isti.cnr.it/


reply via email to

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