Exemple
library(mosaic)
## Warning: package 'mosaic' was built under R version 3.5.1
## Loading required package: dplyr
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## Loading required package: lattice
## Loading required package: ggformula
## Warning: package 'ggformula' was built under R version 3.5.1
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.5.1
## Loading required package: ggstance
## Warning: package 'ggstance' was built under R version 3.5.1
##
## Attaching package: 'ggstance'
## The following objects are masked from 'package:ggplot2':
##
## geom_errorbarh, GeomErrorbarh
##
## New to ggformula? Try the tutorials:
## learnr::run_tutorial("introduction", package = "ggformula")
## learnr::run_tutorial("refining", package = "ggformula")
## Loading required package: mosaicData
## Warning: package 'mosaicData' was built under R version 3.5.1
## Loading required package: Matrix
##
## The 'mosaic' package masks several functions from core packages in order to add
## additional features. The original behavior of these functions should not be affected by this.
##
## Note: If you use the Matrix package, be sure to load it BEFORE loading mosaic.
##
## Attaching package: 'mosaic'
## The following object is masked from 'package:Matrix':
##
## mean
## The following object is masked from 'package:ggplot2':
##
## stat
## The following objects are masked from 'package:dplyr':
##
## count, do, tally
## The following objects are masked from 'package:stats':
##
## binom.test, cor, cor.test, cov, fivenum, IQR, median,
## prop.test, quantile, sd, t.test, var
## The following objects are masked from 'package:base':
##
## max, mean, min, prod, range, sample, sum
g <- function(x, k=2) {x^k}
plotFun(g(x)~x, xlim=c(-1,1))

plotFun(g(x, k=4)~x, xlim=c(-1,1), add=TRUE, col="red")

d1 <- D(expression(x^k), "x")
derivada1 <- function(x, k=2) {eval(d1)}
plotFun(derivada1(x)~x, xlim=c(-1,1))

d2 <- D(d1, "x")
derivada2 <- function(x, k=2) {eval(d2)}
plotFun(derivada2(x)~x, xlim=c(-1,1))

integrate(g, lower=0, upper = 1)
## 0.3333333 with absolute error < 3.7e-15
Solució
f <- function(t, a, c)(a+t/4*exp(c*(2-t/20)))
library(mosaic)
plotFun(f(t, 3, 0.8)~t, xlim=c(0,60))

f(c(10,20,30,40), 3, .8)
## [1] 11.30029 14.12770 14.18869 13.00000
plotFun(f(t, 2, 0.8)~t, xlim=c(0,60), add=TRUE, col="red")

plotFun(f(t, 1, 0.8)~t, xlim=c(0,60), add=TRUE, col="green")

f(c(10,30,50), 3, .8)
## [1] 11.30029 14.18869 11.37900
f(c(10,30,50), 3, 1)
## [1] 14.20422 15.36541 10.58163
f(c(10,30,50), 3, 2)
## [1] 53.213842 23.387114 7.598493
f <- function(t, a=3, c=0.8)(a+t/4*exp(c*(2-t/20)))
df <- D(expression(a+t/4*exp(c*(2-t/20))), "t")
derivada <- function(t, a=3, c=0.8){eval(df)}
plotFun(derivada(t)~t, xlim=c(0,60))

plotFun(derivada(t)~t, xlim=c(0,600))

plotFun(derivada(t)~t, xlim=c(-100,600))

df2 <- D(df, "t")
derivada2 <- function(t, a=3, c=0.8) {eval(df2)}
plotFun(derivada2(t)~t, xlim=c(0,100))

findZeros(derivada2(t)~t, xlim=c(0,600))
## t
## 1 50
findZeros(f(t)-10~t, xlim=c(0,600))
## t
## 1 7.6887
## 2 58.3611
integrate(f, lower=0, upper=10)
## 77.63574 with absolute error < 8.6e-13