Wrong result in elipse equation
조회 수: 1 (최근 30일)
이전 댓글 표시
I have defined an anonymous function elipse
>> xCenter = 0.58;
>> yCenter = 590;
>> a = 0.02;
>> b = 200;
>> elipse = @(x,y) ((x-xCenter)^2)/a^2 + ((y -yCenter)^2)/b^2 - 1;
But the result it's wrong in some case like this:
>> x1 = 0.6;
>> y1 = 590;
>> elipse(x1, y1)
ans =
1.77635683940025e-15
This result should be 0, I have to set something else to fix it? One correct example is:
>> x1 = 0.58;
>> y1 = 390;
>> elipse(x1, y1)
ans =
0
댓글 수: 1
Adam
2018년 7월 2일
1.77e-15 pretty much is 0.
Floating point maths on a computer is not 100% accurate. Numbers cannot be represented to complete accuracy (e.g. some numbers would have an infinite number of decimal places, but even much simpler numbers cannot be represented with 1005 accuracy either just because of how they are represented in a floating-point data type).
Any time you do maths involving floats you should expect an accumulation of insignificant errors. Relative to 590 or 0.6 1e-15 seems pretty insiginificant to me.
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Function Creation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!