필터 지우기
필터 지우기

How to make a composite trapezoidal rule have more than 1 iteration?

조회 수: 2 (최근 30일)
Natalia Wong
Natalia Wong 2015년 12월 23일
댓글: Walter Roberson 2016년 1월 11일
Hi I have written the function for composite trapezoidal rule and I'm required to calculate the volume by integrating 1/(1+x^2) from 0 to 1. I've found the volume (0.7845) but how do i show the number of iterations and absolute error only when the accuracy of the estimation has improved by a decimal place. I'm supposed to fprintf like the as shown below but i don't understand how to make the trapezoidal rule have more than one iteration??
Thanks I'm new to matlab
Iter Pts Vol_est Error
2 3 0.41333333 0.05545687 (1 DP)
5 6 0.41799014 0.00888872 (2 DP)
15 16 0.41878025 0.00098765 (3 DP)
48 49 0.41886937 0.00009645 (4 DP)

답변 (1개)

Walter Roberson
Walter Roberson 2015년 12월 23일
The trapazoidal rule gets more accurate as you sample more finely. The "Iterations" is the number of pieces the range is subdivided in to. 2 pieces takes 3 points, one at the beginning, one in the middle, one in the end. 3 pieces takes 4 points, one at the beginning, one 1/3 of the way, one 2/3 of the way, one at the end. Notice in the table that Pts is always 1 greater than Iter: that is due to this relationship. "Iter" == "Subdivisions"
  댓글 수: 4
Natalia Wong
Natalia Wong 2015년 12월 24일
Thanks Walter but I only need to display the no. of iterations only if the error has improved by a decimal points. How do I check if my error has improved by a decimal point? Is there a built in function?
Walter Roberson
Walter Roberson 2016년 1월 11일
There is no built in function to determine if an error has improved by a decimal point.
I would point out, though, that if abs(current_error) <= abs(recorded_error)/10 then the current error is at least one decimal place better.
If you want to know how many decimal places current_error is, think about log10

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by