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

float otv(float x)
{
 float f;
 f=x*x*x*x-14*x*x*x+60*x*x-70*x;
 return f;
}

float Proiz(float x)
{
 float f;
 f=4*x*x*x-42*x*x+120*x-70;
 return f;
}

void Swann(float &x1,float &x2)
{
 float h,f1,f2;
 h=0.0001;
 x2=x1+h;
 f1=otv(x1);
 f2=otv(x2);
 if (f1<f2)
 {
  x2=x1-h;
  f2=otv(x2);
  while (f2<f1)
  {
   h*=2;
   x1=x2;
   x2-=h;
   f1=otv(x1);
   f2=otv(x2);
  }
  cout<<"Ќ з «м­л© Ё­вҐаў «: ["<<x2<<";"<<x1<<"]";
 }
 else
 {
  while (f1>f2)
  {
   h*=2;
   x1=x2;
   x2+=h;
   f1=otv(x1);
   f2=otv(x2);
  }
  cout<<"Ќ з «м­л© Ё­вҐаў «: ["<<x1<<";"<<x2<<"]";
 }
 if(x1>x2)
 {
  h=x1;
  x1=x2;
  x2=h;
 }
}

void main()
{
  clrscr();
  float e=0.001,a,b,c,x,L,x1=1,x2=0,f1,f2;
  int k=1,d=1;
  Swann(x1,x2);
  f1=Proiz(x1);
  f2=Proiz(x2);
  cout<<endl<<f1<<endl<<f2;
  a=x1;
  b=x2;
  while (d==1)
  {
   x=(a+b)/2;
   L=abs(b-a);
   c=Proiz(x);
   if ((abs(c)<=e)&(L<=e))
   {
    cout<<endl<<x;
    d=2;
   }
   else if (c>0) b=x;
	else a=x;
   k++;
  }
  getch();
}
Соседние файлы в папке all