https://github.com/cran/pracma
Raw File
Tip revision: c1688b374d201c13fb40b4dda2d2a89e34b94ec6 authored by Hans W. Borchers on 23 January 2021, 09:10:02 UTC
version 2.3.3
Tip revision: c1688b3
vectorfield.R
##
##  v e c t o r f i e l d . R
##


vectorfield <- function(fun, xlim, ylim, n = 16,
                        scale = 0.05, col = "green", ...) {
    stopifnot(is.numeric(xlim), length(xlim) == 2,
              is.numeric(ylim), length(ylim) == 2)

	xpts <- linspace(xlim[1], xlim[2], n)
	ypts <- linspace(ylim[1], ylim[2], n)

	M <- meshgrid(xpts, ypts)
	x <- M$X
	y <- M$Y

	px = matrix(1, nrow=n , ncol=n)
	py = fun(x, y);

	plot(xlim, ylim, type="n"); grid()
	quiver(x, y, px, py, scale = scale, col = col, ...)
}


quiver <- function(x, y, u, v,
                    scale = 0.05, angle = 10, length = 0.1, ...) {
    stopifnot(is.numeric(x), is.numeric(y), is.numeric(u), is.numeric(v))
    

	arrows(x, y, x+scale*u, y+scale*v, angle=10, length=length, ...)
}
back to top