Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate Area Between 2 Curves

Tags:

r

I would like to calculate the area between the blue line and the gray diagonal line.

enter image description here

I can calculate the area under the blue line as:

library(zoo)    
id <- order(x)
AUC <- sum(diff(x[id])*rollmean(y[id],2))

(thanks to Calculate the Area under a Curve in R)

Any ideas how to find the area between the blue and gray line?

Thanks in advance EC

like image 874
ECII Avatar asked Oct 23 '11 18:10

ECII


People also ask

What is the formula for area between two curves?

The area between two curves is calculated by the formula: Area = ∫ba[f(x)−g(x)]dx ∫ a b [ f ( x ) − g ( x ) ] d x which is an absolute value of the area. It can never be negative.


1 Answers

The area between curves is the modulus(area(under blue line) - area(under gray line)) Area under blue line is 1/2(b-a)(f(b)-f(a)) where a and b are Xs of limits and f(a),f(b) are Ys of limits. Finding area under gray line can be done using simpson's rule. see this http://en.wikipedia.org/wiki/Simpson%27s_rule They have given rule as well as implementation + accuracy provided you have arrays of xs and ys.

I hope it helps, Saurabh

like image 55
Saurabh Ghorpade Avatar answered Sep 24 '22 03:09

Saurabh Ghorpade