平分法.cpp
来自「最优化实验中的 WOLF 算法 黄金分割法 平分法程序」· C++ 代码 · 共 43 行
CPP
43 行
/*平分法*/
#include<iostream.h>
#include<math.h>
double F(double x)
{
double f;
f=pow(x,2)-x+2;
return f;
}
double Fderivate(double x)
{
double f;
f=x-1;
return f;
}
int main()
{
double a=-1,b=3;
double e=0.01;
double f1,x;
int c;
step1: c=0.5*(b+a);
if(b-a<e)
goto step4;
else
goto step3;
step3: f1=Fderivate(c);
if(f1==0)
goto step4;
else if(f1<0)
{a=c;goto step1;}
else
{b=c;goto step1;}
step4: x=c;
cout<<"x*="<<x;
cout<<"press input enter key to end"<<'\n';
cin.get();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?