采用0.618法求在区间[0,1]内函数f (x)=x(x-1)2(x-2)3的最小值 vc++编程、、、谢~#includeusing namespace std;const float EPS=0.000001;//定义常量float f(float);//定义函数ffloat f(float x){return x*(x-1)^2*(x-2)^3;}void main()

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 21:21:13
采用0.618法求在区间[0,1]内函数f (x)=x(x-1)2(x-2)3的最小值 vc++编程、、、谢~#includeusing namespace std;const float EPS=0.000001;//定义常量float f(float);//定义函数ffloat f(float x){return x*(x-1)^2*(x-2)^3;}void main()

采用0.618法求在区间[0,1]内函数f (x)=x(x-1)2(x-2)3的最小值 vc++编程、、、谢~#includeusing namespace std;const float EPS=0.000001;//定义常量float f(float);//定义函数ffloat f(float x){return x*(x-1)^2*(x-2)^3;}void main()
采用0.618法求在区间[0,1]内函数f (x)=x(x-1)2(x-2)3的最小值 vc++编程、、、谢~
#include
using namespace std;
const float EPS=0.000001;//定义常量
float f(float);
//定义函数f
float f(float x)
{
return x*(x-1)^2*(x-2)^3;
}
void main()
{
float a,b,x1,x2,f1,f2,ε,eps;
couta;
coutb;
couteps;
x1=a+0.382*(b-a);x2=a+0.618*(b-a);
f1=f(x1);f2=f(x2);
while (b-a>eps)//搜索精度循环节
{
=f1-f2;
if (ε>EPS) {a=x1;x1=x2;f1=f2;x2=a+0.618*(b-a);f2=f(x2);}
else if (ε>=-EPS && ε

采用0.618法求在区间[0,1]内函数f (x)=x(x-1)2(x-2)3的最小值 vc++编程、、、谢~#includeusing namespace std;const float EPS=0.000001;//定义常量float f(float);//定义函数ffloat f(float x){return x*(x-1)^2*(x-2)^3;}void main()
帮你改了一下,请看一下.
#include<iostream>
using namespace std;
const float EPS=0.000001;//定义常量
float f(float);
//定义函数f
float f(float x)
{
 return  x*(x-1)*(x-1)*(x-2)*(x-2)*(x-2);//这里的减号是全角字符,必须改为半角;还有符号“^”必须用于整型,无法用于浮点型.
}
void main()
{
 float a,b,x1,x2,f1,f2,alf,eps;//编译器认为ε是非法变量名,暂改名为alf,下同
 cout<<"a=0";cin>>a;
 cout<<"b=1";cin>>b;
 cout<<"eps=0.001";cin>>eps;
 x1=a+0.382*(b-a);x2=a+0.618*(b-a);
 f1=f(x1);f2=f(x2);
 while (b-a>eps)//搜索精度循环节
 {
    alf=f1-f2;//这里等号左边少了变量,是ε?暂时已经换成了alf了.
    if (alf>EPS) {a=x1;x1=x2;f1=f2;x2=a+0.618*(b-a);f2=f(x2);}
    else if (alf>=-1*EPS && alf<=EPS) {a=x1;b=x2;x1=a+0.382*(b-a);x2=a+0.618*(b-a);f1=f(x1);f2=f(x2);}//函数值相等,两边区间均舍去
    else {b=x2;x2=x1;f2=f1;x1=a+0.382*(b-a);f1=f(x1);}
 }
 cout<<"x*="<<(a+b)/2;
   system ("pause");
}

采用0.618法求在区间[0,1]内函数f (x)=x(x-1)2(x-2)3的最小值 vc++编程、、、谢~#includeusing namespace std;const float EPS=0.000001;//定义常量float f(float);//定义函数ffloat f(float x){return x*(x-1)^2*(x-2)^3;}void main() 求级数在收敛区间内的和函数-1 求函数fx=2^x+x-2在区间(0,1)内零点的个数 函数在区间内零点的个数怎么求?比如说,函数f(x)=2^x+x^3-2在区间(0,1),零点的个数为 怎样求函数在区间内的值域? 求函数在区间内的单调性 求函数f(x)=x3次方+x平方+x-1在区间(0,1)内的零点 求函数在所在区间内的极值,y=ln(x^2+x+1),x∈[0,1] 函数y=-x^2+2ax+1-a,在0,1区间内,有最大值3,求a的值.对称轴不一定在(0,1)内,题目只不过告诉你在这个区间内有最大值. 求函数f(x)=x3-lgx在区间(0 10)内零点个数 f(x)=1/x,求该函数在区间【-1,1】内的积分, 求级数∑(2n+1)x^n在其收敛区间内的和函数 求函数f(x)=x3-lgx在区间(1 10)内零点个数 求方程x3-3x+1=0的根一个在区间(-2,-1)内,一个在区间(0,1)内,另一个在区间(1,2)内 若函数f(x)唯一的一个零点同时在区间(0,16),(0,8),(0,4)(0,2)内.那么下列命题正确的是:(C)A函数f(x)在区间(0,1)内有零点B函数f(x)在区间(0,1)或(1,2)内有零点 求详细 求下列幂级数的收敛区间及其在收敛区间内的和函数 若方程5x^2-7x-a=0的一个根在区间(-1,0)内,另一个在区间(1,2)内,求函数a的取值范围 已知函数f(x)=x^5+x-3在区间[1,2]内有零点,求出方程x^5+x-3=0在区间[1,2]内实数解精确到0.1.求过程谢谢