Relative error: not able to get the right answer.

1 回表示 (過去 30 日間)
Krishma Gold
Krishma Gold 2019 年 9 月 3 日
回答済み: Star Strider 2019 年 9 月 3 日
Hi. I am not able to get the correct value of the relative error. Grateful if you please help.
real val approx val relative error
7000 7000 0
5261 5160 1.92
4657 4869 -4.03
Matlab code:
tval = [7000 5261 4657]'
fcast = [7000 5160 4869 ]'
eabs = (tval-fcast)
erel = eabs/tval*100
Ans:
erel =
0 0 0 0 0
1.2625e+000 0 0 0 0
-2.6500e+000 0 0 0 0
Thank you

回答 (1 件)

Star Strider
Star Strider 2019 年 9 月 3 日
You need to do element-wise division:
erel = eabs./tval*100
Then it comes close tho the result you want.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by