Re: [R] question on graphs and finding area under a curve

From: Tuszynski, Jaroslaw W. <JAROSLAW.W.TUSZYNSKI_at_saic.com>
Date: Tue 02 Aug 2005 - 23:22:57 EST


How about:

trapz = function(x, y)
{ # computes the integral of y with respect to x using trapezoidal integration.
  idx = 2:length(x)
  return (as.double( (x[idx] - x[idx-1]) %*% (y[idx] + y[idx-1])) / 2) }

Jarek

====================================================\=======

 Jarek Tuszynski, PhD.                           o / \ 
 Science Applications International Corporation  <\__,|  
 (703) 676-4192                                   ">   \
 Jaroslaw.W.Tuszynski@saic.com                     `    \


-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Renuka Sane Sent: Tuesday, August 02, 2005 8:51 AM
To: r-help@stat.math.ethz.ch
Subject: [R] question on graphs and finding area under a curve

Question on graphs:

The default case for drawing a graph in R, is where a little space is left on the x and y axis before the first tick i.e. even if I say xlim=c(0,1) -- there will be some space between the edge of the x-axis and where 0 is placed. If I want 0 on the edge, how do I do it in R?

Area under the curve:

I have a 45 degree line and a curve above or below it. Is there a way in R to find the area between the two?

Thanks,
Renuka

--
Renuka Sane
http://www.nyx.net/~rsane

	[[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue Aug 02 23:32:28 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:01:08 EST