当前位置:网站首页>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
边栏推荐
- 索引的最左前缀原理
- View partition table format
- [k210 stepping pit] pytorch model is converted to kmodel and used on dock. (ultimately not achieved)
- The data source is SQL server. I want to configure the incremental data of the last two days of the date field updatedate to add
- Incubator course design (April 12, 2021)
- Asp. Net MVC, how can the controller in the folder jump to the controller in the root directory?
- Introduction and examples of parameters in Jenkins parametric construction
- Some problems about pointers
- What the hell is this error? It doesn't affect the execution result, but it always reports errors when executing SQL... Connecting maxcomputer uses
- The structure pointer must be initialized, and the pointer must also be initialized
猜你喜欢

开课!看smardaten如何分解复杂业务场景

不会就坚持64天吧 查找插入位置

MySQL gets the maximum value record by field grouping

Object detection: object_ Detection API +ssd target detection model

9.延迟队列

Locally call tensorboard and Jupiter notebook on the server (using mobaxterm)

14.haproxy+keepalived负载均衡和高可用

伏英娜:元宇宙就是新一代互联网!

不会就坚持60天吧 神奇的字典

No, just stick to it for 59 days
随机推荐
Interview notes of a company
AssertionError(“Torch not compiled with CUDA enabled“)
优炫数据库有办法查到主集群每天传给备集群的日志量吗?
Locally call tensorboard and Jupiter notebook on the server (using mobaxterm)
数据集成这个地方的过滤条件该咋写,用的啥语法?sql语法处理bizdate可以不
Code or script to speed up the video playback of video websites
Svg -- loading animation
Codeforces Round #810 (Div. 2) D. Rain (线段树差分)
C语言:结构体简单语法总结
Introduction and examples of parameters in Jenkins parametric construction
%s. %c, character constant, string constant, const char*, pointer array, string array summary
一个公司的面试笔记
Is there any way for Youxuan database to check the log volume that the primary cluster transmits to the standby cluster every day?
Shielding ODBC load balancing mode in gbase 8A special scenarios?
flink-sql 如何设置 sql执行超时时间
opengauss预检查安装
12.优先级队列和惰性队列
从淘宝,天猫,1688,微店,京东,苏宁,淘特等其他平台一键复制商品到拼多多平台(批量上传宝贝详情接口教程)
Labelme cannot open the picture
小程序:区域滚动、下拉刷新、上拉加载更多
