How to calculate areas between two curves
    3 views (last 30 days)
  
       Show older comments
    
Hi, I am trying to calculate the area between 2 curves, like the curves in the example. how can I do that? i need to do it for numerous curves. for example:
curve1 = 0.0989692836954155  0.0980507726291331  0.0970384942424882  0.0959238642687756  0.0946835230115012  0.0932895426527453  0.0917234414101345  0.0899833361777939  0.0880799175045176  0.0860266166099910  0.0838338165624588  0.0815122241688921  0.0790808183293079  0.0765691735724359  0.0740082611942615  0.0714150109744370  0.0687840002562702  0.0660961982185266  0.0633408591445215  0.0605334186789844  0.0577119283126279  0.0549099837016135  0.0521246262286784  0.0493064410337668  0.0463864265579466  0.0433269656901957  0.0401622148119045  0.0369948482304745  0.0339434273808555  0.0310700336554424  0.0283355565867604  0.0256154390277126  0.0227698364039799  0.0197253032108188  0.0165162589001037  0.0132604339793142  0.0100856539560414  0.00705608433312979  0.00414390520419070  0.00126011311670960  -0.00168087515836256  -0.00470728685876386  -0.00777931393376842  -0.0108223437236493  -0.0137763652358777  -0.0166275807150827  -0.0194053699817629  -0.0221532727932491  -0.0248980315377258  -0.0276373283212288  -0.0303504002037458  -0.0330198377302442  -0.0356479953138234  -0.0382581662754421  -0.0408816871571739  -0.0435395007591687  -0.0462276612423845  -0.0489132001278921  -0.0515429438313566  -0.0540639500652095  -0.0564491415871880  -0.0587162822289883  -0.0609270401183199  -0.0631602051491437  -0.0654683380504257  -0.0678414154262375  -0.0702025201892805  -0.0724441107845225  -0.0744869937547311  -0.0763258409771605  -0.0780301884167565  -0.0796979647924105  -0.0813915450458150  -0.0831000107235126  -0.0847538918055738  -0.0862810535384935  -0.0876617395537291  -0.0889407055687913  -0.0901863868699885  -0.0914280084128462  -0.0926202655878144  -0.0936661942167560  -0.0944851017117010  -0.0950765987265589  -0.0955317126197500  -0.0959792026142186  -0.0965025991348451  -0.0970857599355654  -0.0976248537427748  -0.0979971936784082  -0.0981375159946094  -0.0980693789677133  -0.0978744488061975  -0.0976280832004828  -0.0973512811965863  -0.0970117266659352  -0.0965658180186982  -0.0960022984601718  -0.0953505345655854  -0.0946490274140874  -0.0939045672921766  -0.0930804617168103  -0.0921268508890225  -0.0910285585621825  -0.0898280698249298  -0.0885993015447445  -0.0873885202389159  -0.0861691605202119  -0.0848511725805109  -0.0833450757252396  -0.0816363420439601  -0.0798124498016682  -0.0780156254364824  -0.0763480304908277  -0.0747933756548345  -0.0732111451303255  -0.0714111533314378  -0.0692614235768821  -0.0667603786718409  -0.0640299862198316  -0.0612402469972930  -0.0585185130083402  -0.0559005234682048  -0.0533448681580339  -0.0507873304766895  -0.0481893237342015  -0.0455484554110783  -0.0428742230401606  -0.0401588194395659  -0.0373720900994153  -0.0344847152198117  -0.0314973527521590  -0.0284478520503567  -0.0253875236968152  -0.0223442406787405  -0.0193022360571707  -0.0162158226055582  -0.0130472538030799  -0.00979949533628701  -0.00651840132395182  -0.00326263551629019  -6.46978275955021e-05  0.00308695464274161  0.00623130639618437  0.00939689383627602  0.0125718179232230  0.0157044674859927  0.0187345934343982  0.0216323608594254  0.0244182579956563  0.0271515934524434  0.0298975565122518  0.0326959006014996  0.0355499558460893  0.0384381436033414  0.0413348835694362  0.0442244498787461  0.0471003369965209  0.0499552637674267  0.0527730762089319  0.0555300620350752  0.0582042724852784  0.0607852330098089  0.0632772359685524  0.0656952019141735  0.0680572627194293  0.0703788660744148  0.0726700978098998  0.0749349115119934  0.0771708509599728  0.0793698446030156  0.0815215784199372  0.0836189131634933  0.0856614774888561  0.0876528055437404  0.0895903582871279  0.0914542159085678  0.0932037594633119  0.0947882569263684  0.0961682089749575  0.0973358597356840  0.0983220414694545  0.0991840990406576  0.0999810494109618  0.100749463514579  0.101491991841557  0.102181795550724  0.102777076119958  0.103236524225107  0.103529766651196  0.103642505659486  0.103578790071312  0.103361192422746  0.103026711987708  0.102616355749627  0.102160661923155  0.101668315790760  0.101125306514805  0.100506053328462  0.0997895182605695
curve2 = 0.0979233705137897  0.0971265236237218  0.0962100983680664  0.0951732531801908  0.0940295732921318  0.0927996715455928  0.0914994081914957  0.0901310747814553  0.0886830131545569  0.0871376505664522  0.0854824836837488  0.0837168825991731  0.0818508482248786  0.0798976475711516  0.0778663225449806  0.0757594693674552  0.0735770348096373  0.0713219228581633  0.0690019229734620  0.0666258772848926  0.0641972707835449  0.0617110941097225  0.0591574500654542  0.0565296832339306  0.0538305004897490  0.0510705041038506  0.0482595016767283  0.0453973343461881  0.0424723972742082  0.0394707273565919  0.0363901157600818  0.0332487004314044  0.0300803036227572  0.0269179531200800  0.0237759814696751  0.0206429586890370  0.0174906588429711  0.0142931793519211  0.0110433257888802  0.00775564929948185  0.00445535809164525  0.00116231408780283  -0.00211797234511426  -0.00539079172543316  -0.00866075607673144  -0.0119229455950010  -0.0151643321791277  -0.0183739347452587  -0.0215522870963044  -0.0247108360244328  -0.0278600613435522  -0.0309949724221846  -0.0340901023478994  -0.0371099276230433  -0.0400291168361398  -0.0428488996920562  -0.0455975870303707  -0.0483139488413264  -0.0510240743077294  -0.0537267956530945  -0.0563965924090660  -0.0590007685823951  -0.0615184623244556  -0.0639490633568775  -0.0663061754759337  -0.0686035335325529  -0.0708437658063162  -0.0730170432585355  -0.0751083725876746  -0.0771063542648931  -0.0790068170118251  -0.0808104136259874  -0.0825186420989218  -0.0841332620462102  -0.0856596953781714  -0.0871100403442693  -0.0885005414463808  -0.0898427798924209  -0.0911338585843085  -0.0923532039550240  -0.0934698623868889  -0.0944568623850512  -0.0953039050251711  -0.0960204924892053  -0.0966280493515654  -0.0971468252435081  -0.0975861435805785  -0.0979432299177370  -0.0982094138168430  -0.0983779603168163  -0.0984481442963636  -0.0984242944299945  -0.0983125100203917  -0.0981184404041397  -0.0978470513867209  -0.0975026240862833  -0.0970871430117401  -0.0965977409854134  -0.0960262113700276  -0.0953629151380227  -0.0946036608750354  -0.0937544970678314  -0.0928295550641040  -0.0918418766211620  -0.0907931446959314  -0.0896703066829039  -0.0884527587213748  -0.0871257428847634  -0.0856901110790302  -0.0841605031871529  -0.0825525568535215  -0.0808687188585637  -0.0790943313682225  -0.0772085684843848  -0.0752033439857404  -0.0730962141833495  -0.0709264808342221  -0.0687354234873402  -0.0665433858089091  -0.0643393546969239  -0.0620901803407637  -0.0597627562828031  -0.0573435423804889  -0.0548424189584194  -0.0522799480151879  -0.0496694376712151  -0.0470083934919078  -0.0442857179037050  -0.0414979503559229  -0.0386602396807216  -0.0358016545648326  -0.0329469212607247  -0.0300980236558323  -0.0272303350822878  -0.0243077937579338  -0.0213075608412227  -0.0182371888785399  -0.0151322310750850  -0.0120359025120469  -0.00897484171183305  -0.00594724173567242  -0.00293031071982804  9.97152447586201e-05  0.00314992630652817  0.00620742945844821  0.00925111954565178  0.0122683994296559  0.0152639959233650  0.0182548031110530  0.0212553487222618  0.0242650256655845  0.0272662862639148  0.0302346663592439  0.0331532585426444  0.0360218385628673  0.0388552712068717  0.0416732069951310  0.0444880788137768  0.0472981831266348  0.0500884157992411  0.0528366557643093  0.0555217628600147  0.0581299556606842  0.0606581597598053  0.0631140001777290  0.0655122996136135  0.0678683986327074  0.0701901459079547  0.0724722105774151  0.0746964985889935  0.0768397145002053  0.0788846197818439  0.0808283796166630  0.0826823459746925  0.0844627589936672  0.0861779929224408  0.0878207777480334  0.0893709677112183  0.0908075191248235  0.0921220054100249  0.0933246580807474  0.0944386346620722  0.0954858735024139  0.0964733842970517  0.0973885390769682  0.0982061752390298  0.0989029604108408  0.0994702103621317  0.0999176731180227  0.100266538082477  0.100536336952283  0.100733642744973  0.100848925093361  0.100862864699529  0.100757989211463  0.100528707660401  0.100184042714078  0.0997417138077323  0.0992172193753004  0.0986144352008762
Thanks.
0 Comments
Accepted Answer
  Star Strider
      
      
 on 23 Aug 2018
        I am not certain what you want to do.
Try this:
x = 1:numel(curve1);                                        % Use The Appropriate Vector For The Most Accurate Results
hbar = min([curve1; curve2]);                               % Denoted By Horzontal Bars
vbar = max([curve1; curve2]) - hbar;                        % Denoted By Vertical Bars
SDI = trapz(x,vbar) / (trapz(x,vbar) + trapz(x,hbar));      % Use ‘trapz’ To Do The Integration
Experiment to get the result you want.
2 Comments
More Answers (2)
  Crocola Cool
 on 14 Jan 2021
        Hello,
Someone will be able to help me to calculate the area between the two curves below and You can view the attachment . 
curve1=[0	-2.02194959964403	-4.36158037906568	-7.01837312512906	-10.2043947942008	-13.7792841920484	-17.6342254506087	-21.7954676038832	-25.9504691176317	-29.9069719698352	-33.5035640528856	-36.1766562142324	-38.1766451760081	-39.4940514684918	-39.7288483880309	-39.5166743166741	-38.9455094987348	-38.1173277277474	-37.3322657532744	-36.6120220881433	-36.0340334827880	-35.5339345499250	-34.9873986291563	-34.3459389443170	-33.3536043218965	-32.1006692367832	-30.5867031389627	-28.7448760619758	-26.8520881010716	-24.9717167781644	-23.3012151452208	-21.9798612820762	-20.9272933806502	-20.2197871819685	-19.7578383852495	-19.3043851239042	-18.8070506880975	-17.8779385561834	-16.5584418777308	-14.8395245614530	-12.4558681290326	-9.76353656615456	-6.89728499861483	-4.02474146047447	-1.54269481638132	0.535084133829704	2.00899064930928	2.55097501069675	2.53920343122281	1.97881715581895]
curve2=[0,2.35117790048195,4.88878038758717,7.62217608506737,10.7256074824804,14.1553773946688,17.8238901581741,21.7543493818577,25.6571579618591,29.3485265205192,32.6685920633278,35.0557441436396,36.7646211742757,37.7894359721495,37.7282549656344,37.2150488654992,36.3350653813711,35.1633728197574,33.9758387740986,32.7983764302514,31.6685295659521,30.4790508468238,29.1582655334252,27.6431008056245,25.7042914967358,23.5424773127461,21.1805774837702,18.7483710333778,16.5106192866855,14.5062399534096,13.0189091892566,12.0552486723807,11.4350719106734,11.1916380110256,11.0890290058844,10.8952372203080,10.5396691795425,9.58759935737813,8.22274711644517,6.45437806113839,4.14940065263150,1.71942235579474,-0.716042100630277,-2.89348793865162,-4.47189047470398,-5.53759547415158,-5.90404858304817,-5.36900833248929,-4.35760106978388,-2.88805113989977]
Code %%%%%
clear all
curve1=[0	-2.02194959964403	-4.36158037906568	-7.01837312512906	-10.2043947942008	-13.7792841920484	-17.6342254506087	-21.7954676038832	-25.9504691176317	-29.9069719698352	-33.5035640528856	-36.1766562142324	-38.1766451760081	-39.4940514684918	-39.7288483880309	-39.5166743166741	-38.9455094987348	-38.1173277277474	-37.3322657532744	-36.6120220881433	-36.0340334827880	-35.5339345499250	-34.9873986291563	-34.3459389443170	-33.3536043218965	-32.1006692367832	-30.5867031389627	-28.7448760619758	-26.8520881010716	-24.9717167781644	-23.3012151452208	-21.9798612820762	-20.9272933806502	-20.2197871819685	-19.7578383852495	-19.3043851239042	-18.8070506880975	-17.8779385561834	-16.5584418777308	-14.8395245614530	-12.4558681290326	-9.76353656615456	-6.89728499861483	-4.02474146047447	-1.54269481638132	0.535084133829704	2.00899064930928	2.55097501069675	2.53920343122281	1.97881715581895]
curve2=[0,2.35117790048195,4.88878038758717,7.62217608506737,10.7256074824804,14.1553773946688,17.8238901581741,21.7543493818577,25.6571579618591,29.3485265205192,32.6685920633278,35.0557441436396,36.7646211742757,37.7894359721495,37.7282549656344,37.2150488654992,36.3350653813711,35.1633728197574,33.9758387740986,32.7983764302514,31.6685295659521,30.4790508468238,29.1582655334252,27.6431008056245,25.7042914967358,23.5424773127461,21.1805774837702,18.7483710333778,16.5106192866855,14.5062399534096,13.0189091892566,12.0552486723807,11.4350719106734,11.1916380110256,11.0890290058844,10.8952372203080,10.5396691795425,9.58759935737813,8.22274711644517,6.45437806113839,4.14940065263150,1.71942235579474,-0.716042100630277,-2.89348793865162,-4.47189047470398,-5.53759547415158,-5.90404858304817,-5.36900833248929,-4.35760106978388,-2.88805113989977]
x=1:1:50;
curve2(x) = curve2(round(x)) 
R=curve2(x);
toto= interp1(curve1,curve2,R);
Resultat= trapz(toto,R); 
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


