How can I show that these 2 functions are equal?
a<-function(x) sec^2(x)
b<-function(x) 1 tan^2(x)
I tried using identical
but it’s showing false.
identical(a,b)
[1] FALSE
CodePudding user response:
Using just base R, you can take some range of values for x, compute values for these values for both functions and see if they are equal.
a <- function(x) (1/cos(x))^2
b <- function(x) 1 tan(x)^2
x <- seq(from = -2 * pi, to = 2*pi, length.out = 1e4)
all.equal(a(x), b(x))
# TRUE
CodePudding user response:
In case you have Maxima installed (that is free), you can use rim
:
library(rim)
#> Maxima successfully registered as knitr engine!
maxima.get("trigsimp(1 (tan(x))^2 - (sec(x))^2);")
#> (%o1) 0