Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: cos(pi/2) or sin(-pi) problem Date: Sat, 17 Jan 2009 14:34:02 +0000 (UTC) Organization: Xoran Technologies Lines: 26 Message-ID: <gksq8p$61f$1@fred.mathworks.com> References: <15244285.1232199505643.JavaMail.jakarta@nitrogen.mathforum.org> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-02-blr.mathworks.com Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1232202842 6191 172.30.248.37 (17 Jan 2009 14:34:02 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Sat, 17 Jan 2009 14:34:02 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1440443 Xref: news.mathworks.com comp.soft-sys.matlab:512212 muhaha <muhalkan@yahoo.com> wrote in message <15244285.1232199505643.JavaMail.jakarta@nitrogen.mathforum.org>... > hi guys.. > i wanna ask you somthing.. > i m using MATLAB R2008a and i have a problem with it.. > > > matlab returns " cos(pi/2) = 6.1232e-017" and also " sin(-pi) = -1.2246e-016 ".. and this make me crazy.. both must be zero.. > I'm not sure why it makes you crazy. You must know that machine math is often not exact. This is especially true when it involves numbers like pi, which have to be approximated using a finite number of digits and when it involves functions like cos() and sin() which can only be approximated by arithmetic operations. Nevertheless, you might consider the following if you need to exact zeros. >> cosd(90) ans = 0 >> sind(-180) ans = 0