1、#include#includeclass Vectorpublic:Vector()x1=0;x2=0;x3=0;Vector(double xx1,double xx2,double xx3)x1=xx1;x2=xx2;x3=xx3;friend Vector operator + (Vector v1,Vector v2);friend Vector operator - (Vector friend Vector operator - (Vector friend double operator * (Vector friend Vector operator * (double c,
2、Vector friend Vector operator * (Vector Vector()void display();/private:double x1,x2,x3;Vector operator + (Vector v1,Vector v2)return Vector(v1.x1+v2.x1,v1.x2+v2.x2,v1.x3+v2.x3);Vector operator - (Vector Vector operator - (Vector double operator * (Vector Vector operator * (double c,Vector Vector op
3、erator * (Vector void Vector:display() coutf0“e“endl;h=-h/4;goto step12;step15: cout“极小值点为:lamdak=“lamdakendl;/cout“极值为:f(x)min=“GetFValue(xx)endl;xk+1=xk+lamdak*sk;cout“带入 lamdak 求得“x“k+1“ 点为t“;xk+1.display();gk+1=GradFuction(xk+1);cout“x“k+1“点的梯度为t“;gk+1.display();/step3 结束step4: if (GetModulus(gk
4、+1)precision) goto step6 ;else goto step5;step5:if (kn-1)sk+1=-gk+1+(pow(GetModulus(gk+1),2)/pow(GetModulus(gk),2)*sk;k+;goto step3;if (k=n-1)x0=xn;goto step2;step6: cout“程序结束,求得极小点为:t“;xk+1.display();cout“迭代次数为:t“k+1endl;/* /-以下是测试部分Vector v1(1,2,0),v2(1,2,3),v3(3,1,2),v4,v5,v6,v7(0,3,4);double n;Vector v_arry133=v1,v2,v3;/int ia=;int l=45;v3=v1+v2;v_arry0=v3;/v3=GradFuction(v1);n=ValueFunction(v1);GradFuction(v1).display();v_arry0.display();v4=-v2;v5=v1-v2;v6=-v1-v2;coutnendl;v3.display();v4.display();v5.display();v6.display();coutValueFunction(xk+lamdak*sk)endl;coutGetModulus(v7);*/