Difference between revisions of "R: Matematika Dasar"

From OnnoWiki
Jump to navigation Jump to search
Line 2: Line 2:
  
 
  2 ^ 2
 
  2 ^ 2
 
 
  2 * 2
 
  2 * 2
 
 
  2 / 2
 
  2 / 2
 
 
  2 + 2
 
  2 + 2
 
 
  2 - 2
 
  2 - 2
 
 
  4 * 3 ^ 3
 
  4 * 3 ^ 3
  
Line 26: Line 21:
  
 
  (-4:3) %% 2
 
  (-4:3) %% 2
 
 
  (-4:3) %/% 3
 
  (-4:3) %/% 3
  
Line 43: Line 37:
  
 
  floor(0.39)
 
  floor(0.39)
 +
ceiling(0.39)
 +
 +
 +
==Trigonometry==
  
  ceiling(0.39)
+
  sin(pi/2)
 +
tan(pi/4)
 +
cos(pi)
  
  
Line 90: Line 90:
 
  lfactorial(3000) #lfactorial helps out
 
  lfactorial(3000) #lfactorial helps out
  
==Trigonometry==
 
  
sin(pi/2)
 
tan(pi/4)
 
cos(pi)
 
  
 
==Pranala Menarik==
 
==Pranala Menarik==
  
 
* [[R]]
 
* [[R]]

Revision as of 09:41, 28 November 2019

Contoh operasi matematika

2 ^ 2
2 * 2
2 / 2
2 + 2
2 - 2
4 * 3 ^ 3

vector -4 s/d 3

-4:3

abs remainder

absolute

abs(-4:3)

remainder

(-4:3) %% 2
(-4:3) %/% 3

sign

sign(-4:3)

round

round(7/18,2)
7/118
options(digits=2)
7/118
floor(0.39)
ceiling(0.39)


Trigonometry

sin(pi/2)
tan(pi/4)
cos(pi)


summary functions

sum(1:3)
prod(c(3,5,7))
min(c(1,6,-14,-154,0))
max(c(1,6,-14,-154,0))
range(c(1,6,-14,-154,0))
any(c(1,6,-14,-154,0)<0)
which(c(1,6,-14,-154,0)<0)
all(c(1,6,-14,-154,0)<0) # all checks if criteria is met by each element


Complex

# Plot of Characteristic Function of a U(-1,1) Random Variable
a <- -1; b <- 1
t <- seq(-20,20,.1)
chu <- (exp(1i*t*b)-exp(1i*t*a))/(1i*t*(b-a))
plot(t,chu,"l",ylab=(expression(varphi(t))),main="Characteristic Function of Uniform Distribution [-1, 1]")


# Plot of Characteristic Function of a N(0,1) Variable
mu <- 0; sigma <- 1
t <- seq(-5,5,0.1)
chsnv <- exp(1i*t*mu-.5*(sigma^2)*(t^2))
plot(t,chsnv,"l",ylab=(expression(varphi(t))),main="Characteristic Function of Standard Normal Distribution")


# Plot of Characteristic Function of Poisson Random Variable
lambda <- 6
t <- seq(0,20,.1)
chpois <- exp(lambda*(exp(1i*t)-1))
plot(t,chpois,"l") # Warning omitted and left as exercise
# for the reader to interpret


Spesial

factorial(3)
factorial(3000) # any guess?
lfactorial(3000) #lfactorial helps out


Pranala Menarik