Een kwadratische ontbinden

Kanspuzzels in R

Peter Chi

Assistant Professor of Statistics<br> Villanova University

Wat is de kans dat een kwadratische ontbindt?

Kanspuzzels in R

Een kwadratische ontbinden

$$ x^2 + 3x + 2$$

  • $a=1$
  • $b=3$
  • $c=2$

$$ x^2 + 3x + 2 = (x+2)(x+1)$$

Kanspuzzels in R

Kwadratische formule

Kwadratische vergelijking: $ ax^2 + bx + c = 0 $

 

Kwadratische formule: $ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} $

Discriminant: $ b^2 - 4ac $

Kanspuzzels in R

De discriminant gebruiken

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)
}
Kanspuzzels in R

Is het een volkomen kwadraat?

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
Kanspuzzels in R

De else-voorwaarde

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
Kanspuzzels in R

Geneste for-lussen

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

Kwadraten ontbinden

Kanspuzzels in R

Preparing Video For Download...