From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: conditional operator
Date: Tue, 31 Aug 2010 17:37:04 +0000 (UTC)
Organization: Xoran Technologies
Lines: 27
Message-ID: <i5jek0$ntg$>
References: <ef55682.-1@webcrossing.raydaftYaTP> <gt53q1$qu6$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1283276224 24496 (31 Aug 2010 17:37:04 GMT)
NNTP-Posting-Date: Tue, 31 Aug 2010 17:37:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: comp.soft-sys.matlab:666549

"Matt " <> wrote in message <gt53q1$qu6$>...
> "Dietrich Lueerssen" <> wrote in message <ef55682.-1@webcrossing.raydaftYaTP>...
> > Hi there fellow MATLABers,
> > In C, I would have used the conditional
> > operator "?", as in ( (x==0)?1:sin(x)/x ).
> Seems like a bad idea, since you would have numerical problems in the neighbourhood of x=0.
> It would be better to use a Taylor approximation of sin(x) for x in a near neighbourhood of the origin. This will lead to an approximation of sin(x)./x which is just a polynomial (i.e. no division by x). Once you've accepted the inevitable complexity of this, you will end up writing this as an mfile anyway.... 

I don't think so. Internally, sin() is always implemented using Taylor approximations anyway. It would be redundant to wrap sin() in a 2nd Taylor approximation. In any case, I've never had any numerical problems, even with very small x

>> x=1e-100

x =


>> sin(x)/x

ans =