【算法题】y^7+0.5y=x,给定x求y的牛顿下山法解析
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
#include<cmath>
using namespace std;
#define JD 0.001
#define MAXCount 20000
double Next(double pre,double x){
double ans=0;
ans=pre-(pow(pre,7)+0.5*pre-x)/(7*pow(pre,6)+0.5);
return ans;
}
bool Jd(double pre,double x){
double value=(pow(pre,7)+0.5*pre-x);
if(abs(value)<JD){
return true;
}
return false;
}
bool Wc(double Tyn,double pre,double x){
double value0=(pow(Tyn,7)+0.5*Tyn-x);
double value=(pow(pre,7)+0.5*pre-x);
if(abs(value0)<abs(value)){
return true;
}
return false;
}
int main()
{
double x=0;
cin>>x;
double PYn=0.5*x;
double Tyn=PYn;
int count=0;
while (!Jd(Tyn,x)&&count<MAXCount) {
PYn=Tyn;
Tyn=Next(Tyn,x);
double mark=0.5;
if(!Wc(Tyn,PYn,x)){
Tyn=(Tyn-PYn)*mark+PYn;
mark/=2;
}
++count;
}
cout<<Tyn;
}
网址:【算法题】y^7+0.5y=x,给定x求y的牛顿下山法解析 https://mxgxt.com/news/view/1951574
相关内容
下列函数关系y中.变量y与x成正比例函数关系的是( ) A.y=x2 B.y= C.y=x已知z=f(2xy,x^2+y^2,x^3),且z对x,y的所有二阶偏导数
y=x^3导数y'=3x^2这个求解过程是? 爱问知识人
解析函数y=(x+3)^2(3x+19)^3的主要性质
已知X十y=5,求X的平方十Xy-5(X-3)?
求解函数y=√2
曲线x^3+y^3=1的主要性质
y=(x+1)sin2x+cos^3(2x+1)的导数
y=tan(x+1)如何解? 爱问知识人
4.3.3 对数函数y=logax的图象和性质第1课时对数函数y=logax的图象和性质 练习(含解析)
