当前位置:网站首页>7-18 finding the single root of polynomial by dichotomy
7-18 finding the single root of polynomial by dichotomy
2022-07-03 14:14:00 【Big fish】
Input format :
Enter in 1 The order in the row gives the of the polynomial 4 A coefficient of a3、a2、a1、a0, In the 2 The end points of the interval are given in order in the row a and b. The problem is to ensure that the polynomial has a unique single root in a given interval .
Output format :
Output the root of the polynomial in the interval in one line , Accurate to the decimal point 2 position .
sample input :
3 -1 -3 1
-0.5 0.5
sample output :
0.33
Code :
#include <stdio.h>
float f(float x);
float a,b,c,d;
int main(){
float x, y;
scanf("%f %f %f %f\n%f %f", &a, &b, &c, &d, &x, &y);
float left, mid, right;
left = x;
right = y;
// Title pair “ Midpoint f The value is small but not necessarily the root ” There are requirements , So set the threshold to 0.001
while (left <= right - 0.001 && f(left) * f(right) <= 0)
{
if(f(left)==0){
printf("%.2f",left);
return 0;
}
if(f(right)==0){
printf("%.2f",right);
return 0;
}
mid = (left + right) / 2;
if(f(mid)*f(left)>0){ // Same number
left=mid;
}else{ // Different sign
right=mid;
}
}
printf("%.2f", mid);
return 0;
}
float f(float x)
{
float result;
result = a*x*x*x + b*x*x + c*x + d;
return result;
}
边栏推荐
- Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
- Sendmail无法发送邮件及发送过慢解决
- page owner特性浅析
- Exercise 10-1 judge the three digits that meet the conditions
- Simulated access
- GRPC的四种数据流以及案例
- Exercise 9-3 plane vector addition
- 中国PETG市场预测及战略研究报告(2022版)
- The small project (servlet+jsp+mysql+el+jstl) completes a servlet with login function, with the operation of adding, deleting, modifying and querying. Realize login authentication, prevent illegal log
- 1px problem of mobile terminal
猜你喜欢
必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
[email"/>
Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email
QT learning 24 layout manager (III)
QT learning 17 dialog box and its types
Exercise 9-1 time conversion
FPGA测试方法以Mentor工具为例
7-8 overspeed judgment
28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;
Configure stylelint
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
随机推荐
Generate directories from web content
The small project (servlet+jsp+mysql+el+jstl) completes a servlet with login function, with the operation of adding, deleting, modifying and querying. Realize login authentication, prevent illegal log
JS get DPI, PX to cm, cm to PX
Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them
关于回溯问题中的排列问题的思考(LeetCode46题与47题)
2021年区域赛ICPC沈阳站J-Luggage Lock(代码简洁)
QT learning 19 standard dialog box in QT (top)
Collection of mobile adaptation related articles
Exercise 7-6 count capital consonants
MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
6-9 statistics of single digits (15 points)
Duet date picker (time plug-in that can manually enter the date)
JS continues to explore...
信创产业现状、分析与预测
Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
QT learning 22 layout manager (I)
Toast UI editor (editor allows you to edit your markup document using text or WYSIWYG, with syntax highlighting, scrolling synchronization, real-time preview and chart functions.)
7-9 find a small ball with a balance
泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
虽然不一定最优秀,但一定是最努力的!