Trapezoidal rule with unevenly spaced data points

조회 수: 67 (최근 30일)
Georgia Platt
Georgia Platt 2022년 9월 22일
댓글: Walter Roberson 2022년 9월 22일
I am having a lot of trouble using the trapezoidal method on matlab to determine the area under the curve with no function, just unevenly spaced data points:
(0,0), (1,5), (5,8), (9,6), (3,10), (0,11)
I have absolutely no idea where to start.
  댓글 수: 6
James Tursa
James Tursa 2022년 9월 22일
편집: James Tursa 2022년 9월 22일
@Georgia Platt If you know how to do it by hand, why can't you code that method into MATLAB? Especially once you look at the formulas in the links above. For two points (x1,y1) and (x2,y2) with the ordering x1<x2, the area formed by the trapezoid is simply (x2-x1)*(y1+y2)/2, so why can't you write a loop to sum these up?
Walter Roberson
Walter Roberson 2022년 9월 22일
You can decompose into shapes. There is an initial triangle, and you can get the area for that as 1/2 base times height. There are then a series of trapazoids, and you can calculate their areas. Then there is a final triangle and 1/2 base times height for it. Add the areas all together.
... which is what trapz() will do for you.

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

답변 (1개)

Matt J
Matt J 2022년 9월 22일
See trapz.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by