Path: news.mathworks.com!not-for-mail 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$1@fred.mathworks.com> References: <ef55682.-1@webcrossing.raydaftYaTP> <gt53q1$qu6$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-02-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1283276224 24496 172.30.248.37 (31 Aug 2010 17:37:04 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Tue, 31 Aug 2010 17:37:04 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1440443 Xref: news.mathworks.com comp.soft-sys.matlab:666549 "Matt " <xys@whatever.com> wrote in message <gt53q1$qu6$1@fred.mathworks.com>... > "Dietrich Lueerssen" <Dietrich.Lueerssen@REMOVE-THIS.ogt.co.uk> 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 = 1.0000e-100 >> sin(x)/x ans = 1