MATLAB Answers

Area under the curve in blocs

1 view (last 30 days)
Tiago Dias
Tiago Dias on 15 Apr 2019
Commented: Tiago Dias on 15 Apr 2019
Hello, I would like to know the area under the curve in blocs from 1 to 2, 2 to 3, etc and also the total.
x = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40]
y = [816.347717738660 786.580796557696 363.851047832548 336.220017597815 158.261009949057 129.602592135761 108.274839017586 87.2792863693362 84.6981909884962 68.0648807629763 52.0965547430762 42.3375519238287 36.6589344217772 26.4122184741221 23.3209543975771 22.6645963300025 19.3563124261069 19.0505369873911 18.1401972796281 17.0982948804178 13.5394672532772 9.51007023669543 8.30033459487578 8.05732420060567 7.78827447107891 7.59211717172904 5.53294759143293 4.24011525196683 4.15026586159402 3.86071638283192 3.04425799381248 3.00408977428406 2.89234352480006 2.78175725105813 2.64856273269610 1.50102799563889 1.46442216474623 1.13604322104605 1.11244870832481 0.783468890092899]
areatotal = trapz(x,y)
area1 = trapz(x(1,1:2),y(1,1:2)) % First interval
Is there a better way to compute all the partial areas or i msut do 29 areas like i did for area1? giving every single interval
Thanks for your time

  0 Comments

Sign in to comment.

Accepted Answer

KSSV
KSSV on 15 Apr 2019
Find it by intervel:
x = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40] ;
y = [816.347717738660 786.580796557696 363.851047832548 336.220017597815 158.261009949057 129.602592135761 108.274839017586 87.2792863693362 84.6981909884962 68.0648807629763 52.0965547430762 42.3375519238287 36.6589344217772 26.4122184741221 23.3209543975771 22.6645963300025 19.3563124261069 19.0505369873911 18.1401972796281 17.0982948804178 13.5394672532772 9.51007023669543 8.30033459487578 8.05732420060567 7.78827447107891 7.59211717172904 5.53294759143293 4.24011525196683 4.15026586159402 3.86071638283192 3.04425799381248 3.00408977428406 2.89234352480006 2.78175725105813 2.64856273269610 1.50102799563889 1.46442216474623 1.13604322104605 1.11244870832481 0.783468890092899] ;
areatotal = trapz(x,y) ;
A = zeros(length(x)-1,1) ;
for i = 1:length(x)-1
A(i) = trapz(x(i:i+1),y(i:i+1)) ;
end

  1 Comment

Tiago Dias
Tiago Dias on 15 Apr 2019
ok a loop it is. thanks

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!