fnorm function calculates several different types of function
norms for depending on the argument
fnorm(f, g, x1, x2, p = 2, npoints = 100)
functions given by name or string.
endpoints of the interval.
Numeric scalar or Inf, -Inf; default is 2.
number of points to be considered in the interval.
fnorm returns a scalar that gives some measure of the distance
of two functions
g on the interval
npoints equidistant points in the interval, computes the
function values for
g and applies
p=Inf returns the maximum norm,
fnorm(f, g, x1, x2, p = 1, npoints) / npoints
would return some estimate of the mean distance.
Numeric scalar (or
NA if one of these functions
Another kind of ‘mean’ distance could be calculated by integrating the
f-g and dividing through the length of the interval.
1 2 3 4 5 6 7 8 9 10 11 12 13
xp <- seq(-1, 1, length.out = 6) yp <- runge(xp) p5 <- polyfit(xp, yp, 5) f5 <- function(x) polyval(p5, x) fnorm(runge, f5, -1, 1, p = Inf) #=> 0.4303246 fnorm(runge, f5, -1, 1, p = Inf, npoints = 1000) #=> 0.4326690 # Compute mean distance using fnorm: fnorm(runge, f5, -1, 1, p = 1, 1000) / 1000 #=> 0.1094193 # Compute mean distance by integration: fn <- function(x) abs(runge(x) - f5(x)) integrate(fn, -1, 1)$value / 2 #=> 0.1095285
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.