Скачиваний:
13
Добавлен:
01.05.2014
Размер:
839 б
Скачать
#include <iostream.h>
#include <conio.h>
#include <math.h>
double func(double x)
	{
	 return (10*x*x*x+3*x*x+x+5)*(10*x*x*x+3*x*x+x+5);
	}
void main()
{
 clrscr();
 double x1,x2,f1,f2,a,b,m,l,h1=0.01,eps=0.01,xmin,delta;
 int n=1,k=0;
 delta=0.1*eps;
 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<<" ]";

 while ((b-a)>eps)
	{l=(a+b-delta)/2;
	 m=(a+b+delta)/2;

	 if (func(l)<func(m))
		{
		 b=m;
		}
	 else
		{
		 a=l;
		}
	 k++;
	}
 xmin=(a+b)/2;
 cout<<"\nX* "<<xmin<<"\nN "<<k;
 getch();
}
Соседние файлы в папке all