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

float f (float x)
 { float f;
   f=(2*x*x)-exp(x);
   return f;
 }

float min (float x,float y)
{ float min;
  if (f(x)>f(y))
   {min=y;}
  else
   {min=x;}
  return min;
}

void paul()
 { clrscr();
   float x1=1;
   float h=0.05;
   float x2;
   float e=0.001;
   float d;
   float xx;
    //Swenn
     if (f(x1+h)>f(x1))
    {h=-h;}

   x2=x1+h;
   while (f(x2)<f(x1))
    {
    x1=x2;
    x2=x2+h;
    h=2*h;
    }
    float a,b;
    a=x1-0.5*h;
    b=x2;
    if (a>b)
    {float aa=a;
     a=b;
     b=aa;
    }
//Paul
    int k=1;
    float c=b;
    b=(a+c)/2;

      float e1=0.001;
      float e2=0.001;

    d=0.5*(f(a)*(b*b-c*c)+f(b)*(c*c-a*a)+f(c)*(a*a-b*b))/(f(a)*(b-c)+f(b)*(c-a)+f(c)*(a-b));

    while ((fabs(1-b/d)>e1) | (fabs(1-f(b)/f(d))>e2))
    {
       x1=min(b,d);
       x2=a+c-x1;
       if (x1<x2)
	{ if (f(x1)<f(x2))
	   { c=x2;}
	  else
	   { a=x1;}
	}
       else
	{ if (f(x1)<f(x2))
	   { a=x2;}
	  else
	   { c=x1;}
	}
     k++;
     b=(a+c)/2;
     d=0.5*(f(a)*(b*b-c*c)+f(b)*(c*c-a*a)+f(c)*(a*a-b*b))/(f(a)*(b-c)+f(b)*(c-a)+f(c)*(a-b));
    }
      xx=(d+b)/2;
      cout<<" Kolichestvo iteracii = "<<k<<endl;
      cout<<"X0 = "<<xx<<endl;
      while(!kbhit());

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