fun: Add function

Description Usage Arguments Details See Also Examples

Description

Add a function to plot.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
fun_add(p, fun, samples = NULL, closed = FALSE, color = NULL,
  type = NULL, range = NULL, tip = FALSE, ...)

fun_add_param(p, x, y, samples = NULL, closed = FALSE, color = NULL,
  type = "polyline", range = NULL, tip = FALSE, ...)

fun_add_polar(p, r, scope = NULL, samples = NULL, closed = FALSE,
  color = NULL, type = "polyline", range = NULL, tip = FALSE, ...)

fun_add_imp(p, fun, samples = NULL, closed = FALSE, color = NULL,
  type = NULL, range = NULL, tip = FALSE, ...)

Arguments

p

Plot as initialised by funplot.

fun

Function to plot.

samples

Determine the number of equally spaced points in which the function will be evaluated in the current domain, increasing it will more accurately represent the function using rectangles at the cost of processing speed.

closed

Set to TRUE to render a closed path, y0 will always be 0 and y1 will be fn(x).

color

Color.

type

Rhree representations of functions, default to interval, see details.

range

A list of length 2, the function will be evaluated only within this range.

tip

Set to TRUE to hide the tooltip.

...

Any other parameter.

x, y

Parametric equation.

r

Polar equation.

scope

Scope of r, see fun_scope.

Details

Valid type values:

fun:

Plotting roots can be a challenging problem, most plotters will actually analyze expression of the type x^{a/b}, particularly they will analyze the denominator of the exponent (to plot in the negative x-axis), interval-arithmetic and math.js come bundled with a useful nthRoot function to solve these issues.

See Also

fun_secants, fun_deriv, fun_scope

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# basic equation
funplot() %>%
  fun_add(fun = "sin(x)")

# parametric equation
funplot() %>%
  fun_add_param(
    x = "sin(t) * (exp(cos(t)) - 2 cos(4t) - sin(t/12)^5)",
    y = "cos(t) * (exp(cos(t)) - 2 cos(4t) - sin(t/12)^5)"
   )

# polar equation
funplot() %>%
  fun_add_polar(r = "2 * sin(4 theta)")

# implicit function
funplot() %>%
  fun_add_imp("cos(PI * x) - cos(PI * y)")

# multiple functions
funplot() %>%
  fun_add("sqrt(1 - x * x)") %>%
  fun_add("-sqrt(1 - x * x)")

# samples
funplot() %>%
  fun_add(fun = "sin(x)", samples = 1000)

# closed = TRUE
funplot() %>%
  fun_add("1/x * cos(1/x)", closed = TRUE) %>%
  fun_x("log", domain = list(0.01, 1)) %>%
  fun_y(domain = list(-100, 100))

# color and type
funplot() %>%
  fun_add("x", color = "black") %>%
  fun_add("-x") %>%
  fun_add("-sqrt(x)", type = "scatter", samples = 100) %>%
  fun_add("sqrt(x)", tip = TRUE)

# nthRoot
funplot() %>%
  fun_add("nthRoot(x, 3)^2")

# derivative
funplot() %>%
  fun_add("x^2") %>%
  fun_deriv("2 * x", mouse = TRUE)

# secants
funplot() %>%
  fun_add("x^2") %>%
  fun_secants(x0 = 5, mouse = TRUE)

JohnCoene/funplot documentation built on May 26, 2019, 7:28 a.m.