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

 x1=x0+h1;

 if (df(x1)>0)
	h1=-h1;

 x1=x0+h1;

 while(df(x0)*df(x1)>0)
	{
	 x0=x1;
	 h1=2*h1;
	 x1=x0+h1;
	}

 a=x0;
 if(a>x1)
	{b=a; a=x1;}
 else
	b=x1;
 cout<<"Interval = [ "<<a<<"  "<<b<<" ]";
 xk=(a+b)/2;

 while((fabs(df(xk))>eps)||(abs(b-a)>eps))
	{
	 xk=(a+b)/2;

	 if (df(xk)>0)
		{
		 b=xk;
		}
	 else
		{
		 a=xk;
		}
	 k++;
	}

 xmin=xk;
 cout<<"\nX* "<<xmin<<"\nN "<<k;
 getch();
}




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