computing area between 2 curves

8 vues (au cours des 30 derniers jours)
Vijay
Vijay le 3 Juil 2012
I have two curves from the 2 vetctors as a result of simulation. I want to find the area between these 2 curves. The curves are intersecting many times.
any ideas are appreciated!!

Réponse acceptée

AC
AC le 4 Juil 2012
Hi,
From scratch, you could try something like:
1/2*(abs(C1(2:end)-C2(2:end))+abs(C1(1:end-1)-C2(1:end-1)))*diff(I)'
where C1 and C2 are your curves and I the x-axis.
This will give you an estimate of the integral of C1(t)-C2(t) dt for t in I.
Cheers,
AC
  4 commentaires
Luffy
Luffy le 9 Juil 2012
see doc diff
If X is a vector, then diff(X) returns a vector, one element shorter than X, of differences between adjacent elements.
Vijay
Vijay le 23 Juil 2012
if X is a vector from 1:10 say X-axis. then diff(X) is a vector of '1' nine times. What is the use of multiplying it??

Connectez-vous pour commenter.

Plus de réponses (1)

Luffy
Luffy le 3 Juil 2012
If u know the vectors then try using polyarea & subtract them
  3 commentaires
Luffy
Luffy le 4 Juil 2012
I put too much thought into it,ws thinking about finding area covered by each curve with x axis and then subtracting them to get area between them.
Happy to know polyarea helped you
AC
AC le 4 Juil 2012
Hi,
Substracting the two areas is ok if the curves don't cross and you substract in the right order (that is: highest - lowest). Otherwise you will end up with a wrong result. For example, take sin(x) and cos(x) between 0 and 2: int cos(t)-sin(t) dt = -0.5 approx. int abs(cos(t)-sin(t)) dt= 1.33 approx.
It's the second one that you want. So you should compute the area of the difference in absolute value (see my response below). Cheers,
AC

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by