当前位置:网站首页>函数:用牛顿迭代法求方程的根
函数:用牛顿迭代法求方程的根
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
边栏推荐
- sqqyw(淡然点图标系统)漏洞复现和74cms漏洞复现
- An unhandled exception occurred when C connected to SQL Server: system Argumentexception: "keyword not supported:" integrated
- ES全文索引
- 图书管理系统
- 记一次,修改密码逻辑漏洞实战
- [issue 18] share a Netease go experience
- SQL injection
- Lintcode logo queries the two nearest saplings
- 数据库多表链接的查询方式
- SystemVerilog discusses loop loop structure and built-in loop variable I
猜你喜欢
Statistics, 8th Edition, Jia Junping, Chapter VIII, summary of knowledge points of hypothesis test and answers to exercises after class
网络基础详解
Intranet information collection of Intranet penetration (I)
Statistics 8th Edition Jia Junping Chapter 14 summary of index knowledge points and answers to exercises after class
《统计学》第八版贾俊平第七章知识点总结及课后习题答案
DVWA (5th week)
Intranet information collection of Intranet penetration (2)
Wu Enda's latest interview! Data centric reasons
《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
小程序web抓包-fiddler
随机推荐
【指针】求解最后留下的人
1.支付系统
Xray and burp linkage mining
《统计学》第八版贾俊平第六章统计量及抽样分布知识点总结及课后习题答案
Middleware vulnerability recurrence Apache
Hackmyvm Target Series (3) - vues
XSS之冷门事件
MySQL中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。
Build domain environment (win)
《统计学》第八版贾俊平第三章课后习题及答案总结
flask实现强制登陆
记一次edu,SQL注入实战
网络层—简单的arp断网
SQL injection
This article explains in detail how mockmvc is used in practical work
MySQL interview questions (4)
Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
Ucos-iii learning records (11) - task management
Attack and defense world misc practice area (GIF lift table ext3)