Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Sin(0)=0.xxxxe^-32

Subject: Sin(0)=0.xxxxe^-32

From: Salman Saeed

Date: 13 Apr, 2000 01:10:21

Message: 1 of 6

Im getting weird results at times from both the Sin and Cosine function.
Sin(0.0) gives me results such as 0.xx E-32 and Cos(pi/2) being the same.
Anyone ever run into this bizzare behavior? This typically happens when i do
Sin(theta(n)) where theta is an array and one of its elements is 0.0
Any ideas?
Salman Saeed
ssaeed@kent.edu

Subject: Sin(0)=0.xxxxe^-32

From: Ralf Rabaetje

Date: 13 Apr, 2000 12:13:40

Message: 2 of 6

Salman Saeed wrote:

> Im getting weird results at times from both the Sin and Cosine function.
> Sin(0.0) gives me results such as 0.xx E-32 and Cos(pi/2) being the same.
> Anyone ever run into this bizzare behavior? This typically happens when i do
> Sin(theta(n)) where theta is an array and one of its elements is 0.0
> Any ideas?
> Salman Saeed
> ssaeed@kent.edu

Hi Salman,

I just tried it on my PC (Windows NT 4.0) and MATLAB 5.3.0.620a (R11)

sin(0.0=0
cos(pi/2)=6.1232e-017

So nothing like your results

Bye

Ralf

Subject: Sin(0)=0.xxxxe^-32

From: Mic

Date: 13 Apr, 2000 12:46:52

Message: 3 of 6

salman,
I occasionally get results like this. In some cases, these small non zero
results do worry me (as they may generate a negative answer that is input into
some later function such as a log, which will then generate an error). To get
around this, I wrote a small wrapper for the sin and cos functions that
determine if the input value is close to 0 or pi (or a multiple).. The closeness
is dependence upon the desired accuracy. this wrapper will then return the
appropriate 'exact' answer.
Mic

Salman Saeed wrote:

> Im getting weird results at times from both the Sin and Cosine function.
> Sin(0.0) gives me results such as 0.xx E-32 and Cos(pi/2) being the same.
> Anyone ever run into this bizzare behavior? This typically happens when i do
> Sin(theta(n)) where theta is an array and one of its elements is 0.0
> Any ideas?
> Salman Saeed
> ssaeed@kent.edu

--
Michael Crump
Research Engineer / PhD Candidate
Sir Lawrence Wackett Centre for Aerospace Design Technology
Department of Aerospace Engineering
RMIT University
GPO Box 2476V
Melbourne, Vic 3001
AUSTRALIA

Ph: +61 3 9647 3089
Fax: +61 3 9647 3050

Subject: Sin(0)=0.xxxxe^-32

From: lg@kt.dtu.dk (Lars Gregersen)

Date: 13 Apr, 2000 08:43:43

Message: 4 of 6

On Thu, 13 Apr 2000 01:10:21 GMT, "Salman Saeed" <ssaeed@neo.rr.com>
wrote:

>Im getting weird results at times from both the Sin and Cosine function.
>Sin(0.0) gives me results such as 0.xx E-32 and Cos(pi/2) being the same.
>Anyone ever run into this bizzare behavior? This typically happens when i do
>Sin(theta(n)) where theta is an array and one of its elements is 0.0
>Any ideas?

What platform and what version of Matlab are you using?

My guess it that the argument you're writing as 0.0 is not equal to 0
(zero no more, no less), but rather it is approximately equal to
1e-32.
 
What you're seeing is probably something like this:
» a=[1 1e-32]

a =

    1.0000 0.0000

» b=sin(a)

b =

    0.8415 0.0000

» b(2)

ans =

  1.0000e-032

Note that you normally can't see value of the numbers in a when there
are large numbers in a at the same time. Try the following:

» format short e
» a

a =

  1.0000e+000 1.0000e-032

I hope this helps

  Lars

------------------------------
Lars Gregersen (lg@kt.dtu.dk)
http://www.gbar.dtu.dk/~matlg

Check out my matlab toolboxes at:
http://members.xoom.com/gregersenweb/matlab/

Subject: Sin(0)=0.xxxxe^-32

From: Gerry Thomas

Date: 13 Apr, 2000 07:33:12

Message: 5 of 6

In Matlab, do the following:

double(sin(sym('0'))
double(cos(sym('pi/2'))

and they both give 0. I remember a Cleve's Corner dealing with this.

--
Gerry T.

Salman Saeed wrote in message <189J4.13415$zL2.191468@typhoon.neo.rr.com>...
>Im getting weird results at times from both the Sin and Cosine function.
>Sin(0.0) gives me results such as 0.xx E-32 and Cos(pi/2) being the same.
>Anyone ever run into this bizzare behavior? This typically happens when i
do
>Sin(theta(n)) where theta is an array and one of its elements is 0.0
>Any ideas?
>Salman Saeed
>ssaeed@kent.edu
>
>

Subject: Sin(0)=0.xxxxe^-32

From: Salman Saeed

Date: 14 Apr, 2000 00:58:33

Message: 6 of 6

Thanks a lot for the info.
Salman Saeed
Gerry Thomas <gfthomas@netcom.ca> wrote in message
news:16iJ4.24948$Xk2.98960@tor-nn1.netcom.ca...
> In Matlab, do the following:
>
> double(sin(sym('0'))
> double(cos(sym('pi/2'))
>
> and they both give 0. I remember a Cleve's Corner dealing with this.
>
> --
> Gerry T.
>
> Salman Saeed wrote in message
<189J4.13415$zL2.191468@typhoon.neo.rr.com>...
> >Im getting weird results at times from both the Sin and Cosine function.
> >Sin(0.0) gives me results such as 0.xx E-32 and Cos(pi/2) being the same.
> >Anyone ever run into this bizzare behavior? This typically happens when i
> do
> >Sin(theta(n)) where theta is an array and one of its elements is 0.0
> >Any ideas?
> >Salman Saeed
> >ssaeed@kent.edu
> >
> >
>
>

Tags for this Thread

No tags are associated with this thread.

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.

Contact us