当前位置:网站首页>函数:用牛顿迭代法求方程的根
函数:用牛顿迭代法求方程的根
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
边栏推荐
- JDBC read this article is enough
- What language should I learn from zero foundation. Suggestions
- 《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案
- Hackmyvm target series (7) -tron
- List and data frame of R language experiment III
- Hackmyvm target series (5) -warez
- Spot gold prices rose amid volatility, and the rise in U.S. prices is likely to become the key to the future
- Binary search tree concept
- Low income from doing we media? 90% of people make mistakes in these three points
- Statistics, 8th Edition, Jia Junping, Chapter VIII, summary of knowledge points of hypothesis test and answers to exercises after class
猜你喜欢
内网渗透之内网信息收集(四)
《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案
Solutions to common problems in database development such as MySQL
Database monitoring SQL execution
内网渗透之内网信息收集(一)
Record once, modify password logic vulnerability actual combat
Xray and burp linkage mining
Intranet information collection of Intranet penetration (3)
网络基础详解
Hackmyvm target series (7) -tron
随机推荐
Wu Enda's latest interview! Data centric reasons
《统计学》第八版贾俊平第一章课后习题及答案总结
记一次edu,SQL注入实战
Middleware vulnerability recurrence Apache
Statistics, 8th Edition, Jia Junping, Chapter 11 summary of knowledge points of univariate linear regression and answers to exercises after class
Database monitoring SQL execution
How to understand the difference between technical thinking and business thinking in Bi?
[err] 1055 - expression 1 of order by clause is not in group by clause MySQL
《统计学》第八版贾俊平第十三章时间序列分析和预测知识点总结及课后习题答案
"Gold, silver and four" job hopping needs to be cautious. Can an article solve the interview?
【指针】求解最后留下的人
关于超星脚本出现乱码问题
内网渗透之内网信息收集(四)
Mysql的事务是什么?什么是脏读,什么是幻读?不可重复读?
. Net6: develop modern 3D industrial software based on WPF (2)
Résumé des points de connaissance et des réponses aux exercices après la classe du chapitre 7 de Jia junping dans la huitième édition des statistiques
List and data frame of R language experiment III
A complete collection of papers on text recognition
Harmonyos JS demo application development
Hackmyvm Target Series (3) - vues