当前位置:网站首页>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.33Code :
#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;
}边栏推荐
- Exercise 7-6 count capital consonants
- 7-7 12-24 hour system
- Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
- Leetcode(4)——寻找两个正序数组的中位数
- 7-9 find a small ball with a balance
- Too many files with unapproved license
- Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not
- Exercise 8-7 string sorting
- TS code automatically generates JS
- Article content typesetting and code highlighting
猜你喜欢

关于回溯问题中的排列问题的思考(LeetCode46题与47题)

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

Leetcode(4)——尋找兩個正序數組的中比特數

Redis: redis data structure and key operation commands

FPGA测试方法以Mentor工具为例

Metal organic framework (MOFs) antitumor drug carrier | pcn-223 loaded with metronidazole | uio-66 loaded with ciprofloxacin hydrochloride(

jvm-对象生命周期

泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
[email protected]纳米粒子"/>金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子

QT learning 23 layout manager (II)
随机推荐
Exercise 8-7 string sorting
JS download files through URL links
Generate directories from web content
Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
【吉林大学】考研初试复试资料分享
Message subscription and publishing
Print. JS -- web page file printing
JVM garbage collector
JVM class loading
Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
JS continues to explore...
concat和concat_ws()区别及group_concat()和repeat()函数的使用
Sendmail无法发送邮件及发送过慢解决
Too many files with unapproved license
Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
JS Part III
泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
QT learning 17 dialog box and its types
战略、战术(和 OKR)
Leetcode(4)——尋找兩個正序數組的中比特數