[R] Derivative

David Winsemius dwinsemius at comcast.net
Thu Aug 12 04:13:14 CEST 2010


On Aug 11, 2010, at 9:21 PM, TGS wrote:

> How would I numerically find the x value where the derivative of the  
> function below is zero?
>
> x <- seq(1,2, by = .01)
> y <- 5*cos(2*x)-2*x*sin(2*x)
> plot(x,abs(y), type = "l", ylab = "|y|")

Two ideas:
---minimize abs(diff(y))

abline(v=x[which.min(abs( diff(y) )) ])

---Or maximize the second derivative

plot(x[-(1:2)],diff(diff(y)), type = "l", ylab = "|y|")
abline(v=x[which.max(diff(diff(y)))])


>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list