当前位置:网站首页>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;
}边栏推荐
- Selenium browser (1)
- Exercise 8-2 calculate the sum and difference of two numbers
- Exercise 10-8 recursive implementation of sequential output of integers
- Redis: commandes d'action pour les données de type chaîne
- Current situation, analysis and prediction of information and innovation industry
- Raft 协议
- 小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
- Canvas utility library fabric JS user manual
- Exercise 10-3 recursive implementation of exponential functions
- JVM garbage collector
猜你喜欢

QT learning 23 layout manager (II)

修改数据库中的记录为什么报这个错

7-7 12-24 hour system

Exercise 6-2 using functions to sum special A-string sequences

QT learning 21 standard dialog box in QT (Part 2)

Exercise 10-1 judge the three digits that meet the conditions

Exercise 6-1 classify and count the number of characters
![[Jilin University] information sharing of postgraduate entrance examination and re examination](/img/1d/550a991385b842a21e2b301725407e.png)
[Jilin University] information sharing of postgraduate entrance examination and re examination

QT learning 24 layout manager (III)
[email protected])|制备路线"/>叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线
随机推荐
Exercise 9-1 time conversion
QT learning 17 dialog box and its types
MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
C library function - qsort()
Uniapp skills - dom display and hiding
protobuf与grpc
Interface for querying IP home
超简单手机地图开发
6-9 statistics of single digits (15 points)
八大排序
How to delete an attribute or method of an object
Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
Thinking about the arrangement problem in the backtracking problem (leetcode questions 46 and 47)
[combinatorics] permutation and combination (two counting principles, examples of set permutation | examples of set permutation and circle permutation)
Scroll detection, so that the content in the lower right corner is not displayed at the top of the page, but is displayed as the mouse slides
Solve the problem of dormitory router campus network sharing login
Common plug-ins for vite project development
x86汇编语言-从实模式到保护模式 笔记
jvm-类加载
Reflection -- basic usage