Лабораторная работа: Градієнтні методи
f=3*x1-1.2*x2+exp (0.02*x1*x1+1.3*x2*x2);
return (f);
}
double df1 (double x1, double x2)
{double f1;
f1=3+0.04*x1*exp (0.02*x1*x1+1.3*x2*x2);
return (f1);
}
double df2 (double x1, double x2)
{double f2;
f2=-1.2+2.6*x2*exp (0.02*x1*x1+1.3*x2*x2);
return (f2);
}
double zsech (double a,double b,double x1k,double x2k,double z1,double z2)
{
double eps=0.0001;
double x1,x2,y1,y2,t;
t= (1+sqrt (5)) /2;
x1=a- (b-a) / (t);
y1=f (x1k-x1*z1,x2k-x1*z2);
x2=a+ (b-a) /t;
y2=f (x1k-x2*z1,x2k-x2*z2);
while ( (b-a) >eps) {
if (y1<=y2) { b=x2; x2=x1; y2=y1; x1=a+b-x2; y1=f (x1k-x1*z1,x2k-x1*z2); }
else { a=x1; x1=x2; y1=y2; x2=a+b-x1; y2=f (x1k-x2*z1,x2k-x2*z2); }
}
// if (y1<y2) b=x2;
// else a=x1;
return ( (a+b) /2);