当前位置:网站首页>Find the root of the following equation by chord cutting method, f (x) =x^3-5x^2+16x-80=0
Find the root of the following equation by chord cutting method, f (x) =x^3-5x^2+16x-80=0
2022-07-05 15:54:00 【Lin Yi Lin Yi】
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
double f(double); // Represents the abscissa of the intersection x Function of
double xpoint(double,double); // seek (x1,f(x1)),(x2,f(x2)) The connection between x The intersection of the axes (x,0) Coordinates of
double root(double,double); // Find interval (x1,x2) The real root of
// perform root To be called xpoint function , perform xpoint To be called f function
int main()
{
double x1,x2,f1,f2,x;
do{
cout<<" Please enter the variable x1,x2 Value :";
cin>>x1>>x2;
f1=f(x1);
f2=f(x2);
}while(f1*f2>=0); // When x1 and x2 The cycle of different signs ends
x=root(x1,x2); // Root of solving equation
cout<<setiosflags(ios::fixed)<<setprecision(7); // Specify the output 7 Decimal place
cout<<" The root of the equation :"<<x<<endl;
return 0;
}
double f(double x) // Calculation f(x)
{
double y;
y=x*x*x-5*x*x+16*x-80;
return y;
}
double xpoint(double x1,double x2)
{
double y;
y=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1)); // call f function
return y;
}
double root(double x1,double x2)
{
double x,y,y1;
y1=f(x1);
do{
x=xpoint(x1,x2);
y=f(x);
if(y*y1>0){
y1=y;
x1=x;
}
else
x2=x;
}while(fabs(y)>=0.00001);
return x;
}
边栏推荐
猜你喜欢
研发效能度量指标构成及效能度量方法论
Detailed explanation of C language branch statements
RepLKNet:不是大卷积不好,而是卷积不够大,31x31卷积了解一下 | CVPR 2022
Summary of the third class
18.[stm32] read the ROM of DS18B20 temperature sensor and realize multi-point temperature measurement
Six common transaction solutions, you sing, I come on stage (no best, only better)
具有倍数关系的时钟切换
Five common negotiation strategies of consulting companies and how to safeguard their own interests
21.[STM32]I2C协议弄不懂,深挖时序图带你编写底层驱动
Information collection of penetration test
随机推荐
RepLKNet:不是大卷积不好,而是卷积不够大,31x31卷积了解一下 | CVPR 2022
我们为什么要学习数学建模?
研发效能度量指标构成及效能度量方法论
20. [stm32] realize the function of intelligent garbage can by using ultrasonic module and steering gear
OceanBase社区版之OBD方式部署方式本地安装
go语言编程规范梳理总结
复现Thinkphp 2.x 任意代码执行漏洞
CSRF, XSS science popularization and defense
21.[STM32]I2C协议弄不懂,深挖时序图带你编写底层驱动
vant tabbar遮挡内容的解决方式
JS topic - console log()
19.[STM32]HC_ SR04 ultrasonic ranging_ Timer mode (OLED display)
lvgl 显示图片示例
Bubble sort, insert sort
Value series solution report
Array sorting num ranking merge in ascending order
vlunhub- BoredHackerBlog Social Network
【网易云信】超分辨率技术在实时音视频领域的研究与实践
Memo 00
Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming