# how to calculate the area under a curve?

1,480 ビュー (過去 30 日間)
Davide Cerra 2019 年 7 月 9 日
Answered: Star Strider 2019 年 7 月 9 日
x=[0:100];
y=30-60*cos(2*pi/100*x);
plot (y);
Hello! how con i calculate the area under the curve above? i would also like to calculate portions of that area.
thanks

#### 1 件のコメント

Jan 2019 年 7 月 9 日
I assume that #£ is a typo.
By the way, this is not twitter. No # before the tags. Thanks.

サインイン to comment.

### 件の回答 (2)

Jan 2019 年 7 月 9 日

The area between a curve and the X axis is determined by the integral. So use trapz:
x = 0:100; % Square brackets waste time here only
y = 30 - 60 * cos(2 * pi / 100 * x);
A = trapz(x, y)
You can obtain the integral by hand also here:
30 * (x - 100*sin(pi * x / 50) / pi) + const.
Now insert the limits 0 and 100 to get 3000 as solution.

#### 0 件のコメント

サインイン to comment.

Star Strider 2019 年 7 月 9 日
I would also like to calculate portions of that area.
Use cumtrapz, and then subtract the values of the limits:
x=[0:100];
y=30-60*cos(2*pi/100*x);
Int = cumtrapz(x,y);
Intv = @(a,b) max(Int(x<=b)) - min(Int(x>=a));
SegmentArea = Intv(25, 75)
SegmentArea =
3409.2309572264
Checking:
SegmentArea = integral(@(x)30-60*cos(2*pi/100*x), 25, 75)
SegmentArea =
3409.85931710274

#### 0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。