Скачиваний:
13
Добавлен:
01.05.2014
Размер:
740 б
Скачать
#include <stdio.h>
//#include <conio.h>
#define e .001
#define b .01

double f1 = f(x1);

void swen(Type x1,Type h,Type &a,Type &b)
{
  //Step 1
  int count = 0;
  Type x2 = 0;
  x2 = x1+h;
  double f1 = f(x1);
  double f2 = f(x2);
  if (f(x2)>f(x1))
  {
	 h = -h;
	 x2 = x1+h;
  }
  //step 2
  Type last = x1;
  for (;;)
  {
	 h = 2*h;
	 last = x1;
	 x1 = x2;
	 x2 += h;
	 f1 = f(x1);
	 f2 = f(x2);
	 count++;
	 if (f(x2)>f(x1))
	   break;
  }
  //step 3
  a = x1;  b = x2;
  if (a>b)
	vSwap(a,b);
  cout<<"\n\nResult of metod SWENN: ";
  cout<<"\n\ta = "<<a<<"\tb = "<<b;
  cout<<"\n\tNumber of iteration: "<<count;
}

int main ()
{
 int a;float x1;
 scanf("%e",&x1);
 sven();
 return 0;
}
Соседние файлы в папке all