Kanspuzzels in R
Peter Chi
Assistant Professor of Statistics<br> Villanova University
$$ x^2 + 3x + 2$$
$$ x^2 + 3x + 2 = (x+2)(x+1)$$
Kwadratische vergelijking: $ ax^2 + bx + c = 0 $
Kwadratische formule: $ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} $
Discriminant: $ b^2 - 4ac $
Kwadratische formule: $ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} $
Discriminant: $ b^2 - 4ac $
Voorbeeld. $x^2 + 3x + 2$
if(3^2 - 4*1*2 < 0){
return(FALSE)
}
Kwadratische formule: $ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} $
Discriminant: $ b^2 - 4ac $
Voorbeeld. $x^2 + 3x + 2$
sqrt_dscr <- sqrt(3^2 - 4*1*2)
sqrt_dscr == round(sqrt_dscr)
TRUE
is.integer werkt niet:
is.integer(sqrt_dscr)
FALSE
Vierkantswortel wordt niet berekend:
value <- (-1)
if(value < 0){
print("The value is negative.")
} else {
print(sqrt(value))
}
"The value is negative."
Waarde is positief, dus de wortel wordt berekend:
value <- 4
if(value < 0){
print("The value is negative.")
} else {
print(sqrt(value))
}
2
for(i in 1:10){
for(j in 1:10){
print(i+j)
}
}
2
3
4
5
6
7
8
9
10
11
3
4
5
...
Kanspuzzels in R