การแยกตัวประกอบสมการกำลังสอง

Probability Puzzles in R

Peter Chi

Assistant Professor of Statistics<br> Villanova University

ความน่าจะเป็นที่สมการกำลังสองจะแยกตัวประกอบได้คือเท่าไร?

Probability Puzzles in R

การแยกตัวประกอบสมการกำลังสอง

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

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

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

Probability Puzzles in R

สูตรกำลังสอง

สมการกำลังสอง: $ ax^2 + bx + c = 0 $

 

สูตรกำลังสอง: $ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} $

ดิสคริมิแนนต์: $ b^2 - 4ac $

Probability Puzzles in R

การใช้ดิสคริมิแนนต์

สูตรกำลังสอง: $ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} $

ดิสคริมิแนนต์: $ b^2 - 4ac $

 

ตัวอย่าง. $x^2 + 3x + 2$

if(3^2 - 4*1*2 < 0){
  return(FALSE)
}
Probability Puzzles in R

เป็นกำลังสองสมบูรณ์หรือไม่?

สูตรกำลังสอง: $ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} $

ดิสคริมิแนนต์: $ b^2 - 4ac $

ตัวอย่าง. $x^2 + 3x + 2$

sqrt_dscr <- sqrt(3^2 - 4*1*2)
sqrt_dscr == round(sqrt_dscr)
TRUE

 

 

 

is.integer ใช้งานไม่ได้:

is.integer(sqrt_dscr)
FALSE
Probability Puzzles in R

เงื่อนไข else

ไม่มีการคำนวณรากที่สอง:

value <- (-1)
if(value < 0){
  print("The value is negative.")
} else {
  print(sqrt(value))
}
"The value is negative."

ค่าเป็นบวก จึงคำนวณรากที่สอง:

value <- 4
if(value < 0){
  print("The value is negative.")
} else {
  print(sqrt(value))
}
2
Probability Puzzles in R

การวนซ้ำ for แบบซ้อน

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
...
Probability Puzzles in R

มาฝึกกันเถอะ!

Probability Puzzles in R

Preparing Video For Download...