필터 지우기
필터 지우기

Calculating accuracy of decimal places and print out the values

조회 수: 3 (최근 30일)
Lorenne
Lorenne 2018년 5월 6일
댓글: Walter Roberson 2018년 5월 10일
How to find the accuracy of decimal places between the integral approximation and the MATLAB built-in integral function? Eg: if my approximation is 0.50000000 and the true value is 0.52359878, and error is 0. 0 2359878, there is one 0 in front of the error value, '0.0', so the Decimal place will be 1, and when approximation is 0.51666667, error will be 0. 00 693211, there is two 0 , so decimal place will be 2.
Also, how do i only print the approximation and the error values when the decimal place has increased by 1?

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 5월 6일
편집: Ameer Hamza 2018년 5월 6일
You can use the following formula to calculate the number of zeros after decimal position and first non-zero digit
floor(-log10(error))
To only print when accuracy is increased do the following
bestAccuracy = 0;
while bestAccuracy < 10
integralValue = % calculate your integral here
error = % calculate yor error here
accuracy = floor(-log10(error));
if accuracy > bestAccuracy
bestAccuracy = accuracy;
disp(error);
end
end
This loop will run till best accuracy will become 10.
  댓글 수: 4
Ameer Hamza
Ameer Hamza 2018년 5월 6일
Yes. If you want to have 8 zeros after decimal points, then use bestAccuracy < 8.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jaidyn Lai
Jaidyn Lai 2018년 5월 10일
ENG1060 assignment I see

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by