> On 16 Dec 2015, at 22:09 , David Winsemius <dwinsem...@comcast.net> wrote:
> 
>>> and look watch the graphs.
>> 
>> Looks fine to me, at least the non-plotmath version?
> 
> Here's a plotmath version that positions the expression in the center of the 
> plot region.

Just in case: I wasn't implying an issue with the plot math version, I just 
never tried it.

(And by the way, the story was that I sketched a solution and Bill wrapped it 
as a function).

For completeness, here's a version of the trapezoidal rule (the only slightly 
tricky bit is that polygon() does not vectorize like rect() does):

showIntegral.tr <- function (f, xmin, xmax, n = 16)
{
  curve(f(x), from = xmin, to = xmax, lwd = 2, col = "blue")
  abline(h = 0)
  dx <- (xmax - xmin)/n
  right <- xmin + (1:n) * dx
  left <- right - dx
  fl <- f(left)
  fr <- f(right)
  PP <- Vectorize(function(l,r,fl,fr)
     polygon(c(l, r, r, l), c(0, 0, fr, fl) , density=20, border = "red"))
  PP(left,right, fl, fr)
  sum((fr+fl)/2 * dx)
}

showIntegral.tr(sqrt, xmin=0, xmax=4)


-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd....@cbs.dk  Priv: pda...@gmail.com

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to