R/plot_trapezoid.R

#' plot
#'
#' Plots the parabolas created in a Trapezoid rule
#' numerical integration.
#'
#' @param Trapezoid The Trapezoid object to plot.
#' @export
setMethod("plot",
		  signature="Trapezoid",
		  definition=function(x=NULL, y=x, ...){
		  	plot(x=NULL, y=NULL, xlim=range(x@x), ylim=range(x@y), xlab="x", ylab="y", main="Numerical Integration (Trapezoid Method)")
		  	points(x@x, x@y, pch=16)
		  	# There is one fewer dot than the length of the range,
		  	# because the range is bordered by lines.
		  	line.range = 1:length(x@x)
		  	dot.range  = 1:length(x@x - 1)
		  	segments(x@x[dot.range], x@y[dot.range], x@x[dot.range+1], x@y[dot.range+1])
		  	segments(x@x[line.range], 0, x@x[line.range], x@y[line.range])
		  }
)
alexjweil/integrateIt documentation built on May 10, 2019, 8:54 a.m.