Скачиваний:
13
Добавлен:
01.05.2014
Размер:
857 б
Скачать
#include <iostream.h>
#include <conio.h>
#include <math.h>
double func(double x)
	{
	return (2*x*x+(16/x));
	}
void main()
{
 clrscr();
 double x1,x2,f1,f2,a,b,m,l,h1=0.01,eps=0.01,xmin;
 int n=1,k=0;
 cout << "Vvedite proizvolnuu tochku: ";
 cin>>x1;
 x2=x1+h1;
 f1=func(x1);
 f2=func(x2);

 if (f2>f1)
	h1=-h1;
 x2=x1+h1;

 f1=func(x1);
 f2=func(x2);

 while (f2<f1)
	{
	 x1=x2;
	 h1=2*h1;
	 x2=x1+h1;
	 f1=func(x1);
	 f2=func(x2);
	 n++;
	}
  a=x2-3*h1/2;
   if(a>x2)
	{b=a; a=x2;}
   else
	b=x2;
 cout<<"Interval = [ "<<a<<"  "<<b<<" ]";
 l=a+0.382*(b-a);
 m=a+0.618*(b-a);
		while ((b-a)>eps)
		{
		if (func(l)<func(m))
			{b=m;
			 m=l;
			 l=a+0.382*(b-a);
			}
		else
			{a=l;
			 l=m;
			 m=a+0.618*(b-a);
			};
		k++;
		};
	xmin=(a+b)/2;
	cout<<"\nX* "<<xmin<<"\nN "<<k;
	getch();
}


Соседние файлы в папке all