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:
Problem with machine precision

Subject: Problem with machine precision

From: Hermano Cappa

Date: 10 Aug, 2011 09:23:13

Message: 1 of 2

Hello,

I have a problem with the machine presion namely if I calculate 1+cosd(120) +cosd(240) than the result in Matlab is 5.5511e-017 instead of zero. This gives me a lot of problems later in my program. Why is this not equal to zero?

Thanks

Steven

Subject: Problem with machine precision

From: Walid Maghroum

Date: 10 Aug, 2011 10:24:10

Message: 2 of 2

Well Hermano, this is due to the representation of floating points in the computer. To learn more about this you can read this link:
http://www.mathworks.com/support/solutions/en/data/1-16FOQ/

actually you should program your code differently in state of using
if (a-b = 0)
you can use for example
if(a-b<eps)
or so

hope it helps
Walid

"Hermano Cappa" wrote in message <j1tim1$njb$1@newscl01ah.mathworks.com>...
> Hello,
>
> I have a problem with the machine presion namely if I calculate 1+cosd(120) +cosd(240) than the result in Matlab is 5.5511e-017 instead of zero. This gives me a lot of problems later in my program. Why is this not equal to zero?
>
> Thanks
>
> Steven

Tags for 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