当前位置:网站首页>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;
}边栏推荐
猜你喜欢

Configure stylelint

jvm-运行时数据区

QT learning 22 layout manager (I)

泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东

Generate directories from web content

allegro,orcad, net alias,port,off-page connector之间的异同点和如何选取

全局事件总线

QT learning 20 standard dialog box in QT (middle)

28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;

JS Part 2
随机推荐
Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not
Uio-66-cooh loaded bendamostine | hydroxyapatite (HA) coated MIL-53 (FE) nanoparticles | baicalin loaded manganese based metal organic skeleton material
Exercise 10-8 recursive implementation of sequential output of integers
全局事件总线
中国PETG市场预测及战略研究报告(2022版)
protobuf与grpc
[combinatorics] permutation and combination (two counting principles, examples of set permutation | examples of set permutation and circle permutation)
小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
Exercise 9-1 time conversion
Redis: redis data structure and key operation commands
Message subscription and publishing
Exercise 7-6 count capital consonants
Exercise 9-3 plane vector addition
Too many files with unapproved license
simpleParallax. JS (create poor visual effects for website pictures)
JS download files through URL links
MongoDB索引
How to bold text in AI
Duet date picker (time plug-in that can manually enter the date)