Skip to content
Prev 74764 / 398502 Next

question on graphs and finding area under a curve

Hi,

To find the area lying between the curve y = y(x) and 45 degree line (which,
assuming it goes through the origin, is y = x), you can use the following
function based on trapezoidal rule:

trap.rule <- function(x,f) {sum(diff(x)*(f[-1]+f[-length(f)]))/2}

trap.rule(x,f=y-x)

This area will be negative if y(x) is below the 45 degree line.

However, your question is not complete, I think.  You need to specify the
interval of integration. For this you may need to determine the points of
intersection of the two curves, which involves the solution of a fixed point
problem.

Hope this helps,
Ravi.