Dear All: I am trying to explain to my students how to calculate the definite integral using the Riemann sum. Can someone help me to graph the area under the curve of the function, showing the curve as well as the rectangles between 0 and 4.. *f(x) = x^3 - 2*x * over the interval [0 , 4] with many thanks steve -- Steven M. Stoline 1123 Forest Avenue Portland, ME 04112 sstoline at gmail.com [[alternative HTML version deleted]]
Hi Steve, Give RSeek.org a try ... http://rseek.org/?q=show+area+under+curve There a loads of examples and blogs on this topic at RSeek.org. Under the 'Support' tab there is an exchange between two USM folk on this very topic. Cheers, Ben On Nov 27, 2015, at 7:52 AM, Steven Stoline <sstoline at gmail.com> wrote:> Dear All: > > I am trying to explain to my students how to calculate the definite > integral using the Riemann sum. Can someone help me to graph the area under > the curve of the function, showing the curve as well as the rectangles > between 0 and 4.. > > *f(x) = x^3 - 2*x * > > over the interval [0 , 4] > > > > with many thanks > steve > > -- > Steven M. Stoline > 1123 Forest Avenue > Portland, ME 04112 > sstoline at gmail.com > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.Ben Tupper Bigelow Laboratory for Ocean Sciences 60 Bigelow Drive, P.O. Box 380 East Boothbay, Maine 04544 http://www.bigelow.org
Something like this? f <- function(x) x^3-2*x curve(f(x), from=0, to=4) abline(h=0) n <- 16 dx <- 4/n right <- (1:n)*dx left <- right - dx mid <- right - dx/2 fm <- f(mid) points(mid, fm) rect(left,0,right,fm) sum(fm*dx) 1/4 * 4^4 - 4^2 -pd On 27 Nov 2015, at 13:52 , Steven Stoline <sstoline at gmail.com> wrote:> Dear All: > > I am trying to explain to my students how to calculate the definite > integral using the Riemann sum. Can someone help me to graph the area under > the curve of the function, showing the curve as well as the rectangles > between 0 and 4.. > > *f(x) = x^3 - 2*x * > > over the interval [0 , 4] > > > > with many thanks > steve > > -- > Steven M. Stoline > 1123 Forest Avenue > Portland, ME 04112 > sstoline at gmail.com > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
many thanks steve On Fri, Nov 27, 2015 at 9:20 AM, peter dalgaard <pdalgd at gmail.com> wrote:> Something like this? > > f <- function(x) x^3-2*x > curve(f(x), from=0, to=4) > abline(h=0) > n <- 16 > dx <- 4/n > right <- (1:n)*dx > left <- right - dx > mid <- right - dx/2 > fm <- f(mid) > points(mid, fm) > rect(left,0,right,fm) > > sum(fm*dx) > > 1/4 * 4^4 - 4^2 > > > -pd > > > On 27 Nov 2015, at 13:52 , Steven Stoline <sstoline at gmail.com> wrote: > > > Dear All: > > > > I am trying to explain to my students how to calculate the definite > > integral using the Riemann sum. Can someone help me to graph the area > under > > the curve of the function, showing the curve as well as the rectangles > > between 0 and 4.. > > > > *f(x) = x^3 - 2*x * > > > > over the interval [0 , 4] > > > > > > > > with many thanks > > steve > > > > -- > > Steven M. Stoline > > 1123 Forest Avenue > > Portland, ME 04112 > > sstoline at gmail.com > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at 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. > > -- > Peter Dalgaard, Professor, > Center for Statistics, Copenhagen Business School > Solbjerg Plads 3, 2000 Frederiksberg, Denmark > Phone: (+45)38153501 > Office: A 4.23 > Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com > > > > > > > > > >-- Steven M. Stoline 1123 Forest Avenue Portland, ME 04112 sstoline at gmail.com [[alternative HTML version deleted]]