Precision problem while solving Cody Problems
조회 수: 2 (최근 30일)
이전 댓글 표시
While solving Cody problems, I have often encountered that my answer is not accepted because of the precision doesn't match the required answer. Matlab always rounds the double format to 4 digits after decimal. My logic seems correct on paper, but fails while applied as a code due to the precision problem.
Here's an example
Can somebody help me how to change this or how I can output more than 4 digits?
I know I can use vpa, but cody doesn't accept vpa and also it is symbolic.
댓글 수: 6
Walter Roberson
2020년 10월 18일
MATLAB defaults to format short because for most work, about 4 digits is as much accuracy as can be justified by the precision of the inputs, and much of the time people do not care about the additional digits and the digits just make it more difficult to see the information they are looking for. Most of the time, it is more valuable to use the saved space to output more entries per line instead of fewer more precise entries. In the case where people do need the higher precision then format longg command can be used or the system preference can be modified. I personally often need higher precision but most people do not.
채택된 답변
goc3
2020년 11월 10일
There are quite a few problems that have been posted to Cody that erroneously use isequal() to test answers, rather than using a tolerance. Each faulty problem needs to have its test suite fixed/updated to properly test against your function output. We have made an effort to fix many of these faulty problems. If you find a Cody problem that still exhibits this discrepancy in required precision, post a comment on that problem to alert us.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Arithmetic Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!