当前位置:网站首页>Function: find the root of the equation by Newton iterative method
Function: find the root of the equation by Newton iterative method
2022-07-06 14:35:00 【|Light|】
requirement
Find the root of the equation by Newton iterative method . The equation is ax3+bx2+cx+d=0, The coefficient is entered by the user , seek x stay 1 Nearby roots .
,
Code
#include<math.h>
#define EPSILON 1E-6
/* * function 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;
}
/* * function f(x)=a*x**3+b*x**2+c*x+d The derivative of */
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;
}
/* * In this function, the equation is solved by iterative method in 1 Nearby roots , You can call the above f Functions and f The derivative of */
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;
}
test
Test input
10 5 -11 -3.28351
Output
Where is the equation 1 The root nearby is 0.97
边栏推荐
- xray與burp聯動 挖掘
- Intranet information collection of Intranet penetration (4)
- Intranet information collection of Intranet penetration (I)
- Record an edu, SQL injection practice
- Intranet information collection of Intranet penetration (3)
- Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class
- Pointeurs: maximum, minimum et moyenne
- 内网渗透之内网信息收集(三)
- 浙大版《C语言程序设计实验与习题指导(第3版)》题目集
- JVM memory model concept
猜你喜欢
线程的实现方式总结
Constants, variables, and operators of SystemVerilog usage
内网渗透之内网信息收集(一)
Hackmyvm target series (2) -warrior
Data mining - a discussion on sample imbalance in classification problems
Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
How to turn wechat applet into uniapp
List and data frame of R language experiment III
Library management system
Statistics 8th Edition Jia Junping Chapter 14 summary of index knowledge points and answers to exercises after class
随机推荐
链队实现(C语言)
函数:求方程的根
浅谈漏洞发现思路
MySQL中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
Library management system
SystemVerilog discusses loop loop structure and built-in loop variable I
How to understand the difference between technical thinking and business thinking in Bi?
关于超星脚本出现乱码问题
《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案
“Hello IC World”
函数:求1-1/2+1/3-1/4+1/5-1/6+1/7-…+1/n
XSS (cross site scripting attack) for security interview
【指针】查找最大的字符串
Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
Data mining - a discussion on sample imbalance in classification problems
DVWA (5th week)
Proceedingjoinpoint API use
【指针】求字符串的长度
《统计学》第八版贾俊平第三章课后习题及答案总结
Detailed explanation of three ways of HTTP caching