Round off errors (Decimal Place)

4 ビュー (過去 30 日間)
Mantej Sokhi
Mantej Sokhi 2022 年 9 月 25 日
編集済み: Mantej Sokhi 2023 年 10 月 22 日
How would I round off each number (let's say n = 1:1000) upto 5 decimal digits first and then round up their sum to 5 digit decimal arithmetic ?
  1 件のコメント
Torsten
Torsten 2022 年 9 月 25 日
編集済み: Torsten 2022 年 9 月 25 日

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

回答 (1 件)

Bala Tripura Bodapati
Bala Tripura Bodapati 2022 年 9 月 28 日
Hi Mantej,
It is my understanding that you would like to round off individual elements of a vector up to 5 decimal points and then round off the sum of elements of a vector up to 5 decimal points.
The following code illustrates an example of performing the above operations on a vector containing 10 elements:
X=1:10
Y=round(1./x,5)
answer=round(sum(Y),5)
By default, MATLAB's output display format is 'short' displaying 4 digits after the decimal point. This behaviour can be modified using the 'format' option. To verify the above operations, the output display format can be changed to 'long' using following command:
format long
After the above command is executed in the command line, the rounded values of individual vector elements and their sum can be verified.
Please refer the below documentation for more information

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by