当前位置:网站首页>函数:用牛顿迭代法求方程的根
函数:用牛顿迭代法求方程的根
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
边栏推荐
- SystemVerilog discusses loop loop structure and built-in loop variable I
- Hackmyvm target series (1) -webmaster
- A complete collection of papers on text recognition
- "Gold, silver and four" job hopping needs to be cautious. Can an article solve the interview?
- 《統計學》第八版賈俊平第七章知識點總結及課後習題答案
- XSS (cross site scripting attack) for security interview
- Constants, variables, and operators of SystemVerilog usage
- 《统计学》第八版贾俊平第四章总结及课后习题答案
- 我的第一篇博客
- Detailed explanation of network foundation routing
猜你喜欢

Record an API interface SQL injection practice

图书管理系统

Windows platform mongodb database installation

链队实现(C语言)

Interview Essentials: what is the mysterious framework asking?

Intranet information collection of Intranet penetration (I)

《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案

Only 40% of the articles are original? Here comes the modification method

《英特尔 oneAPI—打开异构新纪元》

Network technology related topics
随机推荐
Based on authorized access, cross host, and permission allocation under sqlserver
How to understand the difference between technical thinking and business thinking in Bi?
Middleware vulnerability recurrence Apache
Sword finger offer 23 - print binary tree from top to bottom
"Gold, silver and four" job hopping needs to be cautious. Can an article solve the interview?
【指针】求二维数组中最大元素的值
Data mining - a discussion on sample imbalance in classification problems
Fire! One day transferred to go engineer, not fire handstand sing Conquest (in serial)
Attack and defense world misc practice area (simplerar, base64stego, no matter how high your Kung Fu is, you are afraid of kitchen knives)
Lintcode logo queries the two nearest saplings
List and data frame of R language experiment III
浙大版《C语言程序设计实验与习题指导(第3版)》题目集
JDBC transactions, batch processing, and connection pooling (super detailed)
What language should I learn from zero foundation. Suggestions
xray與burp聯動 挖掘
Circular queue (C language)
线程的实现方式总结
Network layer - simple ARP disconnection
Intranet information collection of Intranet penetration (4)
《统计学》第八版贾俊平第二章课后习题及答案总结