当前位置:网站首页>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;
}边栏推荐
- [clean up the extraordinary image of Disk C]
- Global event bus
- Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
- GRPC的四种数据流以及案例
- 叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线
- jvm-类加载
- JVM object lifecycle
- UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
- Redis:Redis的数据结构、key的操作命令
- FPGA test method takes mentor tool as an example
猜你喜欢

Exercise 10-8 recursive implementation of sequential output of integers

Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions

Programmable logic device software testing

TS code automatically generates JS

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

Example analysis of QT learning 18 login dialog box
![[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

Redis: operation command of string type data

JS first summary

Exercise 6-6 use a function to output an integer in reverse order
随机推荐
编程语言:类型系统的本质
[combinatorics] permutation and combination (examples of combinatorial number of multiple sets | three counting models | selection problem | combinatorial problem of multiple sets | nonnegative intege
Redis: commandes d'action pour les données de type chaîne
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Vite project commissioning
GRPC的四种数据流以及案例
7-9 find a small ball with a balance
天图投资冲刺港股:资产管理规模249亿 投了小红书与奈雪
JS Part III
JS input number and standard digit number are compared. The problem of adding 0 to 0
1px problem of mobile terminal
PCB中常用快捷键
愉悦资本新双币基金近40亿元完成首次关账
交联环糊精金属有机骨架负载甲氨蝶呤缓释微粒|金属-有机多孔材料UiO-66负载黄酮苷类药物|齐岳
Duet date picker (time plug-in that can manually enter the date)
Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
Raft 协议
selenium 浏览器(1)
Canvas utility library fabric JS user manual