Скачиваний:
13
Добавлен:
01.05.2014
Размер:
1.13 Кб
Скачать
#include <math.h>
#include <conio.h>
#include <stdlib.h>
#include <iostream.h>
#include <stdio.h>

 double func(double x)
	{
	 double f=(10*x*x*x+3*x*x+x+5)*(10*x*x*x+3*x*x+x+5);
	 return f;
	}
double df(double x)
	{
	 double fproizv=(20*x*x*x+6*x*x+2*x+10)*(30*x*x+6*x+1);
	 return fproizv;
	}

void main()
{
 clrscr();
 double x0,x1,xk,xmin,a,b,z,w,gamma,eps=0.01,h1=0.01;
 int k=1;

 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<<" ]";
   while ((fabs(df(xk))>eps))
	{
	 z=df(a)+df(b)+3*(func(a)-func(b))/b;
	 w=sqrt(z*z-df(a)*df(b));
	 gamma=(z-df(a)+w)/(df(b)-df(a)+2*w);

	 if ((gamma<1)&&(gamma>0))
		{
		 xk=a+gamma*(b-a);
		}
	 else
		{
		 if (gamma<0)
			{
			xk=a;
			}
		 if (gamma>1)
			{
			xk=b;
			}
        }
	 if (df(xk)>0)
		{
		b=xk;
		}
	 else
		{
		 a=xk;
		}
	 k++;
	}
 xmin=xk;
 cout<<"\nX* "<<xmin<<"\nN "<<k;
 getch();
}


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