이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I have a 5X2 matrix its values are:
-1.0000 1.0000
-1.0000 1.0000
-1.0000 -3.0000
-3.0000 -1.0000
-1.0000 -3.0000
but when i put in the statement below i get the response 'no', can someone tell me why, pretty pleas
if (final(1,:) == final(2,:))
display('yes')
else
display('no')
end
채택된 답변
per isakson
2012년 4월 8일
0 개 추천
There are two problems with your code:
- "==" doesn't work well with floating point precision (EDIT: understatement)
- "if (final(1,:) == final(2,:))" should read "if all(final(1,:) == final(2,:))"
--- EDIT ---
Make sure you read the link provided by Walter and Floating points by Cleve Moler. The simple rule is: never test if two floating point values are equal.
--- EDIT ---
The internal representation and what is displayed differ. With Matlab the display format can be controlled with the function, FORMAT. With format('hex') the full internal precision is shown. Try
>> v1 = 1/3;
>> v2 = 0.333;
>> v3 = 0.3333;
>> format('hex')
>> v1
v1 =
3fd5555555555555
>> v2
v2 =
3fd54fdf3b645a1d
>> v3
v3 =
3fd554c985f06f69
>>
>> format('short')
댓글 수: 7
Tlale
2012년 4월 8일
i just want to test if row 1 is equal to row 1, so i think the explanation for "2.", but for "1.", what do you suggest, if i were to just change the precision are you saying it should work properly, giving a "yes" response in this case instead of a "no"
Walter Roberson
2012년 4월 8일
http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
Tlale
2012년 4월 9일
Thank you very much, that helped alot, but how are you suppose to learn these nitty gritty stuff about matlab without first going through the trouble with them, is there some link that you might have that gives a comprehensive explanation of matlab. i mean ive read alot of matlab books and havent come across this: ie, "introduction to matlab and advanced concepts= book", "Advanced matlab", "Matlab for engineers" and etc, none of these books hint on that.........is there some link i can read, with a comprehensive study of matlab?
per isakson
2012년 4월 9일
This issue is not specific to Matlab, which might explain why it is little discussed in Matlab books. Did you look up Walter's link: "... what everybody should know ..."? If Matlab is your first programming language there is obviously a problem.
Walter Roberson
2012년 4월 9일
Also, reading the whole FAQ will help prepare you for the future.
Tlale
2012년 4월 11일
O.k it did help, thank you, and no matlab is not my first programming laguage but it is the first where 2 numbers that look exactli the same can be defined as different numbers but i understand the solution. Guess its mathematical. like 0.333 = 1/3 but 0.333x3 is not 1 even though 1/3 x 3 is one.
Walter Roberson
2012년 4월 11일
Yes, it is exactly like that. It is a problem in every finite positional number system.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
