sin(pi)

少年你写程序关注这种旁支末节干嘛,pi在运算中不需要多精确,sym(pi)是符号变量,进行的已经不算是数值运算了,它可以有任意充分的精度.matlab是调用其他符号计算引擎计算的.
具体可学习下符号计算.
举个例子
pi在系统内被认为是一个充分精确地数 比如 3.1415926535898
sym(pi)是符号,相当于π.
运算中sin(3.1415926535898)是数值运算sin(π)是符号运算

  1. Create Account
  2. Log In
  1. File Exchange
  2. Answers
  3. Newsgroup
  4. Link Exchange
  5. Blogs
  6. Trendy
  7. Cody
  8. Contest
  9. MathWorks.com
  • About the MATLAB Newsgroup
  • Post A New Message
  • E-mail this page
Got Questions? Get Answers.
 
Add thread to My Watch List What is a Watch List?

Thread Subject: sin(pi) does not equal zero

Subject: sin(pi) does not equal zero

From: Steve Waikam SIU

Date: 11 Dec, 1998 20:12:23

Message: 1 of 6

Reply to this message Add author to My Watch List View original format Flag as spam

Hi,
I'm using MATLAB 5.1 for Windows, I found that sin(pi) doesn't equal
zero. Is it a bug? Is there any methods to correct it?

sin(pi)

ans =

  1.2246e-016

Steve

Subject: sin(pi) does not equal zero

From: 112358etc@my-dejanews.com

Date: 11 Dec, 1998 18:27:23

Message: 2 of 6

Reply to this message Add author to My Watch List View original format Flag as spam

In article <36710C27.8DA4BC75@ee.cityu.edu.hk>,
  Steve Waikam SIU wrote:
> Hi,
> I'm using MATLAB 5.1 for Windows, I found that sin(pi) doesn't equal
> zero. Is it a bug? Is there any methods to correct it?
>
> sin(pi) = 1.2246e-016


Steve:
    I don't want to disappoint you, but "pi" is not really pi,
"sin" is not really the sine function, and indeed, NO matlab
trigonometric, logarithmic or exponential function is the true
algebraic/calculus function you learned about in school. The
reality is that Matlab uses only a finite number of decimal
places (roughly 16), and that the algorithms that it uses
to ESTIMATE these functions do only that: estimate them.
Incidentally, the same situation occurs with scientific
calculators, and has since they first hit the market in
the '70's, and for those of us old enough to remember,
there was only limited accuracy in all of those books full
of tables (all based on estimates anyway). The important
point is to be able to interpret the output intelligently,
and to be able to understand when the output really should
be zero. So far, that is one edge that humans retain over
computers. For the moment. Finally, if you want to know
more about this issue of what the computer is really doing,
look at a book on numerical analysis, or better yet, take
a course somewhere. It's a fascinating subject!

Jeff Stuart, Ph.D
Department of Mathematics
University of Southern Mississippi
jeff.stuart_REMOVE_THIS@usm.edu (Isn't spam grand?)

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

Subject: sin(pi) does not equal zero

From: Matt Jones

Date: 11 Dec, 1998 18:27:54

Message: 3 of 6

Reply to this message Add author to My Watch List View original format Flag as spam

In article <36710C27.8DA4BC75@ee.cityu.edu.hk> Steve Waikam SIU,
wksiu@ee.cityu.edu.hk writes:
>Hi,
>I'm using MATLAB 5.1 for Windows, I found that sin(pi) doesn't equal
>zero. Is it a bug? Is there any methods to correct it?
>
>sin(pi)
>
>ans =
>
> 1.2246e-016
>

Hmm, that's very strange. I'm using Matlab 5.2.1 on the Mac, and here's
what I get:

»format short
»sin(pi)

ans =

     0

»format long
»sin(pi)

ans =

     0

»format long e
»sin(pi)

ans =

     0


Matt Jones

Subject: sin(pi) does not equal zero

From: rayn@mathworks.com (raymond s. norris)

Date: 11 Dec, 1998 14:06:29

Message: 4 of 6

Reply to this message Add author to My Watch List View original format Flag as spam

Hi Steve-

Given what Jeff says in his post, that doesn't prevent compilers from
doing the right thing. In some instances, the result can depend heavily
on the vendor's compiler interpretation of sin(pi) (for example.)

If you are looking for zeroness, perhaps a better approach would be the
following:

       >> value=sin(pi);
       >> if abs(value-0)        value =
            0

type
>> help eps

for more info on eps.

hth,
-raymond


In article <74ro68$22h$1@nnrp1.dejanews.com>, 112358etc@my-dejanews.com
says...
> In article <36710C27.8DA4BC75@ee.cityu.edu.hk>,
> Steve Waikam SIU wrote:
> > Hi,
> > I'm using MATLAB 5.1 for Windows, I found that sin(pi) doesn't equal
> > zero. Is it a bug? Is there any methods to correct it?
> >
> > sin(pi) = 1.2246e-016
>
>
> Steve:
> I don't want to disappoint you, but "pi" is not really pi,
> "sin" is not really the sine function, and indeed, NO matlab
> trigonometric, logarithmic or exponential function is the true
> algebraic/calculus function you learned about in school. The
> reality is that Matlab uses only a finite number of decimal
> places (roughly 16), and that the algorithms that it uses
> to ESTIMATE these functions do only that: estimate them.
> Incidentally, the same situation occurs with scientific
> calculators, and has since they first hit the market in
> the '70's, and for those of us old enough to remember,
> there was only limited accuracy in all of those books full
> of tables (all based on estimates anyway). The important
> point is to be able to interpret the output intelligently,
> and to be able to understand when the output really should
> be zero. So far, that is one edge that humans retain over
> computers. For the moment. Finally, if you want to know
> more about this issue of what the computer is really doing,
> look at a book on numerical analysis, or better yet, take
> a course somewhere. It's a fascinating subject!
>
> Jeff Stuart, Ph.D
> Department of Mathematics
> University of Southern Mississippi
> jeff.stuart_REMOVE_THIS@usm.edu (Isn't spam grand?)

Subject: sin(pi) does not equal zero

From: moler@mathworks.com (Cleve Moler)

Date: 11 Dec, 1998 14:20:35

Message: 5 of 6

Reply to this message Add author to My Watch List View original format Flag as spam

Steve Waikam SIU wrote:

> I'm using MATLAB 5.1 for Windows, I found that sin(pi) doesn't equal
> zero. Is it a bug? Is there any methods to correct it?
>
> sin(pi)
>
> ans =
>
> 1.2246e-016
>
> Steve


Hi.

I can't easily use Greek letters in newsgroup followups, so let me
instead use Pi to denote the classic mathematical quantity which is
the ratio of the circumference of a circle to its diameter and the
half-period of the sin function. MATLAB's floating point variable pi
is only an approximation to Pi. The graph of sin(x) is very nearly
linear near x = Pi, so

   sin(pi) - sin(Pi) = -(pi - Pi) + a term of size (pi - Pi)^3.

By definition, sin(Pi) is zero, so

   sin(pi) ~= Pi - pi

In other words, the value of sin(pi) should be very close to the
(negative of) the error in pi as an approximation to Pi.

We can ask the symbolic toolbox to compare our floating point pi with
whatever it uses to compute Pi.

   >> double(sym('pi') - sym(pi,'f'))

   ans =
       1.224646799147353e-016

So, Steve found that MATLAB actually computes the right answer for sin(pi).

Also note that, when applied to floating point numbers, cos(x) is never 0
and tan(x) is a bounded function.

Of course, we could arrange that sin(pi) comes out to be zero. In fact,
this happens on some machines because the underlying elementary math
function library believes that pi is equal to Pi. But then sin(10*pi)
and sin(1000000*pi) should also be zero, but they aren't.

   -- Cleve Moler
   moler@mathworks.com

Subject: sin(pi) does not equal zero

From: spamthis@my-dejanews.com

Date: 11 Dec, 1998 19:28:17

Message: 6 of 6

Reply to this message Add author to My Watch List View original format Flag as spam

In article <36710C27.8DA4BC75@ee.cityu.edu.hk>,
  Steve Waikam SIU wrote:
> Hi,
> I'm using MATLAB 5.1 for Windows, I found that sin(pi) doesn't equal
> zero. Is it a bug? Is there any methods to correct it?
>
> sin(pi)
>
> ans =
>
> 1.2246e-016
>
> Steve
>
>

Yes it is a bug.. I like to call it the "finite precision bug", or sometimes,
the "anal retention bug". I suspect it is the same bug that leads to:


1-0.1*exp(log(10))= -2.220446049250313e-16


To fix it, you just need to buy a computer with enough bits of precision...
enough that you lose interest and wander off before the
still-slightly-incorrect answer is returned. Until you make this wise
purchase, you can convince yourself that nothing insidious lurks within by
looking at:

k=0:1000;
plot(sin(k*pi))

This reassures me (at least) that no grave errors were made in the sin()
function.
The errors remain small (as does the mean of these errors). For much larger
k, the mean drifts slightly, but if you need better precision, you might wish
to consider using a .mex file and doing it yourself.

Helpful as ever,
Claude

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rss Feed for this Thread

Contact us

  • Site Help
  • Patents
  • Trademarks
  • Privacy Policy
  • Preventing Piracy
  • Terms of Use
  • RSS
  • Google+
  • Facebook
  • Twitter
  • Featured MathWorks.com Topics:
  • New Products
  • Support
  • Documentation
  • Training
  • Webinars
  • Newsletters
  • MATLAB Trials
  • Careers


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部