MATLAB Answers

Precision problem while solving Cody Problems

3 ビュー (過去 30 日間)
Dyuman Joshi
Dyuman Joshi 2020 年 10 月 18 日
編集済み: Dyuman Joshi 2021 年 4 月 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 件のコメント
Dyuman Joshi
Dyuman Joshi 2020 年 10 月 19 日
"...why does it output answer upto 4 digits only?"
I guess this was my misunderstanding of the format and precision used by MATLAB and partially a mistake as I forgot about format long.
"Note that the square brackets are totally superflous: square brackets are a concatentation operator (not a "list" operator, which MATLAB does not have) and should be removed completely"
I was not aware of this. Thanks for the info.

サインインしてコメントする。

採用された回答

goc3
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 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by