X

Using trigonometric functions in R

R uses radiant as input for trigonometric functions.

# calculating rad
pi/2
90*pi/180 # transforming degree into radiant
degr<-c(0:360)
degr
rad<-grad*(pi/180)
rad

Now we can plot the function.

sin(rad)
plot(sin(rad))

And by playing with the functions we get a funny graphic output.

plot(asin(sin(rad)))
plot(asin(sin(rad)),type="l")
points(sin(rad))
points(sin(rad)*-1,col="green")
lines(asin(sin(rad))*-1)
lines(1/sin(rad),col="red")
lines(1/sin(rad)*-1,col="blue")
points(x=91,y=0)
points(x=271,y=0)


And if we include the tangent, the graphic looks like this:

tan(rad)
tangens <- tan(rad)
tangens[91]<-0
tangens[271]<-0
plot(tangens,type="l")
lines(sin(rad),type="l",col="red")
lines(cos(rad),type="l",col="green")
lines(tangens,type="l",col="red")
lines(1/tangens,type="l",col="green")
# dividing by 10 for visual reasons
lines(tangens/10,type="l",col="red")
lines(1/tangens/10,type="l",col="green")

plot(tangens,type="l")
lines(1/tangens,type="l")
plot(tangens,type="l")
lines(1/tangens,type="l",col="green")

 

Martin Stoppacher: