当前位置:网站首页>函数:用牛顿迭代法求方程的根
函数:用牛顿迭代法求方程的根
2022-07-06 09:24:00 【|光|】
要求
用牛顿迭代法求方程的根。方程为ax3+bx2+cx+d=0,系数由用户输入,求x在1附近的根。
,
代码
#include<math.h>
#define EPSILON 1E-6
/* * 函数f(x)=a*x**3+b*x**2+c*x+d */
double f(double a,double b,double c, double d, double x)
{
double t;
t=a*x*x*x+b*x*x+c*x+d;
return t;
}
/* * 函数f(x)=a*x**3+b*x**2+c*x+d的导函数 */
double derivatives(double a,double b,double c, double d, double x)
{
double t;
t=3*a*x*x+2*b*x+c;
return t;
}
/* * 在该函数中用迭代法求解方程在1附近的根,可以调用上面的f函数和f的导函数 */
double fun(double a,double b,double c,double d)
{
double x1,x=1;
do
{
x1=x;
x = x1 - f(a,b,c,d,x)/derivatives(a,b,c,d,x);
}
while(fabs(x1-x)>=1e-3);
return x;
}
测试
测试输入
10 5 -11 -3.28351
输出
方程在1附近的根为0.97
边栏推荐
- AQS details
- DVWA (5th week)
- Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
- Xray and burp linkage mining
- Statistics 8th Edition Jia Junping Chapter 5 probability and probability distribution
- msf生成payload大全
- 《统计学》第八版贾俊平第二章课后习题及答案总结
- MSF generate payload Encyclopedia
- Interpretation of iterator related "itertools" module usage
- 关于交换a和b的值的四种方法
猜你喜欢
Hcip -- MPLS experiment
How does SQLite count the data that meets another condition under the data that has been classified once
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
Hackmyvm target series (2) -warrior
On the idea of vulnerability discovery
Lintcode logo queries the two nearest saplings
. Net6: develop modern 3D industrial software based on WPF (2)
记一次edu,SQL注入实战
《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
外网打点(信息收集)
随机推荐
攻防世界MISC练习区(SimpleRAR、base64stego、功夫再高也怕菜刀)
JDBC看这篇就够了
MySQL中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
Detailed explanation of network foundation routing
小程序web抓包-fiddler
Web vulnerability - File Inclusion Vulnerability of file operation
Mathematical modeling idea of 2022 central China Cup
Solutions to common problems in database development such as MySQL
XSS之冷门事件
内网渗透之内网信息收集(三)
《统计学》第八版贾俊平第七章知识点总结及课后习题答案
《统计学》第八版贾俊平第十一章一元线性回归知识点总结及课后习题答案
HackMyvm靶機系列(3)-visions
Interview Essentials: what is the mysterious framework asking?
Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]
{1,2,3,2,5}查重问题
Constants, variables, and operators of SystemVerilog usage
【指针】求解最后留下的人
Windows platform mongodb database installation