因式分解二次式

R 中的概率谜题

Peter Chi

Assistant Professor of Statistics<br> Villanova University

二次式可因式分解的概率是多少?

R 中的概率谜题

二次式因式分解

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

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

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

R 中的概率谜题

求根公式

二次方程: $ ax^2 + bx + c = 0 $

 

求根公式: $ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} $

判别式: $ b^2 - 4ac $

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)
}
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
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
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
...
R 中的概率谜题

来分解一些二次式

R 中的概率谜题

Preparing Video For Download...