当前位置:网站首页>Realize the effect of univariate quadratic equation through JS. Enter the coefficients of a, B and C to calculate the values of X1 and x2
Realize the effect of univariate quadratic equation through JS. Enter the coefficients of a, B and C to calculate the values of X1 and x2
2022-07-29 04:16:00 【Xiao Yang should work hard】
Catalog
The second step : We know , The expression of univariate quadratic equation is edit
The third step : We define three variables to receive a,b,c
Step five : Next, we judge △ Size , When △ Less than 0 when , The equation has no real root
Step six : When △ be equal to 0 when x1 be equal to x2
Step seven : When △ Greater than 0 when ,
First step : frame
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
</script>
</body>
</html>
The second step : We know , The expression of univariate quadratic equation is 
The root formula is

So here we need to define x1,x2.a,b,c,△,disp
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
var x1, x2, a, b, c, disp
</script>
</body>
</html>
The third step : We define three variables to receive a,b,c
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
var x1, x2, a, b, c, disp
var a = prompt(' Please enter a')
var b = prompt(' Please enter b')
var c = prompt(' Please enter c')
</script>
</body>
</html>
Step four : Next, we judge △ The situation of , To determine whether there is a real root , So let's first define △(disp)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
var x1, x2, a, b, c, disp
var a = prompt(' Please enter a')
var b = prompt(' Please enter b')
var c = prompt(' Please enter c')
disp = (Math.pow(b, 2) - (4 * a * c))
</script>
</body>
</html>
here Math.pow() Is a function that defines the square
Step five : Next, we judge △ Size , When △ Less than 0 when , The equation has no real root
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
var x1, x2, a, b, c, disp
var a = prompt(' Please enter a')
var b = prompt(' Please enter b')
var c = prompt(' Please enter c')
disp = (Math.pow(b, 2) - (4 * a * c))
if (disp < 0) {
alert(' I'm sorry , The equation has no real root ')
}
</script>
</body>
</html>
Step six : When △ be equal to 0 when x1 be equal to x2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
var x1, x2, a, b, c, disp
var a = prompt(' Please enter a')
var b = prompt(' Please enter b')
var c = prompt(' Please enter c')
disp = (Math.pow(b, 2) - (4 * a * c))
if (disp < 0) {
alert(' I'm sorry , The equation has no real root ')
} else if (disp == 0) {
x1 = (-b / 2 * a)
x2 = (-b / 2 * a)
alert('x1=x2 The value is ' + x1)
}
</script>
</body>
</html>
Step seven : When △ Greater than 0 when ,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
var x1, x2, a, b, c, disp
var a = prompt(' Please enter a')
var b = prompt(' Please enter b')
var c = prompt(' Please enter c')
disp = (Math.pow(b, 2) - (4 * a * c))
if (disp < 0) {
alert(' I'm sorry , The equation has no real root ')
} else if (disp == 0) {
x1 = (-b / 2 * a)
x2 = (-b / 2 * a)
alert('x1=x2 The value is ' + x1)
} else {
x1 = ((-b + Math.sqrt(disp)) / 2 * a)
x2 = ((-b - Math.sqrt(disp)) / 2 * a)
}
alert('x1 The value of is ' + x1 + '\n' + 'x2 The value of is ' + x2);
</script>
</body>
</html>
there Math.sqrt() It means root
边栏推荐
- RMAN do not mark expired backups
- Introduction and examples of parameters in Jenkins parametric construction
- 15.federation
- C语言力扣第61题之旋转链表。双端队列与构造循环链表
- 从淘宝,天猫,1688,微店,京东,苏宁,淘特等其他平台一键复制商品到拼多多平台(批量上传宝贝详情接口教程)
- 不会就坚持60天吧 神奇的字典
- C语言:typedef知识点总结
- opengauss预检查安装
- The return value of the function is the attention of the pointer, the local variables inside the static limit sub function, and how the pointer to the array represents the array elements
- 不会就坚持70天吧 数组中第k大的数
猜你喜欢
随机推荐
从淘宝,天猫,1688,微店,京东,苏宁,淘特等其他平台一键复制商品到拼多多平台(批量上传宝贝详情接口教程)
Database SQL statement realizes function query of data decomposition
Machine vision Series 1: Visual Studio 2019 dynamic link library DLL establishment
Do you have a boss to help me check whether the parameter configuration of the Flink SQL connection Kafka authentication Kerberos is wrong
Interview notes of a company
2021 sist summer camp experience + record post of School of information, Shanghai University of science and technology
9. Delay queue
对一个元素使用多种变形的方法
Beginner: array & String
The principle of inverse Fourier transform (IFFT) in signal processing
C语言:浅谈各种复杂的声明
No, just stick to it for 64 days. Find the insertion location
The difference between dynamic, VaR and object in fluent
C语言力扣第61题之旋转链表。双端队列与构造循环链表
%s. %c, character constant, string constant, const char*, pointer array, string array summary
数据库SQL语句实现数据分解的函数查询
Not for 61 days. The shortest word code
How to set the SQL execution timeout for flick SQL
SQL server how to judge when the parameter received by the stored procedure is of type int?
不会就坚持61天吧 最短的单词编码










