else
if(y2<y3) {a=x1;b=x3;}
else {a=x2;x2=x3;y2=y3;}
}
x=x2;
y=y2;
E=(b-a)/2;
cout<<"x="<<x<<endl;
cout<<"y="<<y<<endl;
cout<<"E="<<E<<endl;
cout<<"Enter"<<endl;
int zad;
scanf("%i",&zad);
cout<<endl;
}
Метод Фибоначчи.
#include "math.h"
#include "iostream.h"
#include "stdio.h"
void main()
{
double a=0,b=1,x,E,y,x1,x2,y1,y2,d;
int N=23;
int F[23];
F[0]=F[1]=1;
for (int i=2;i<=23;i++)
{F[i]=F[i-1]+F[i-2];
cout<<i<<" "<<F[i]<<" "<<endl;
}
d=(b-a)/(20000*F[23]);
x1=a+((b-a)*F[21])/F[23];
y1=x1*x1+4*exp(-0.25*x1);
x2=a+((b-a)*F[22])/F[23];
y2=x2*x2+4*exp(-0.25*x2);
for(i=2;i<22;i++)
{
if(y1<y2) {b=x2; x2=x1; y2=y1; x1=a+b-x2; y1=x1*x1+4*exp(-0.25*x1);}
else {a=x1; x1=x2; y1=y2; x2=a+b-x1; y2=x2*x2+4*exp(-0.25*x2);}
}
if(y1<y2) {b=x2; x2=x1; y2=y1;}
else a=x1;
x1=x2-d;
y1=x1*x1+4*exp(-0.25*x1);
if(y1<y2) b=x2; else a=x1;