7. Метод Фибоначчи
7.1. Текст программы на С++
#include<iostream.h>
#include<math.h>
#include<conio.h>
#include<stdio.h>
#include "stdafx.h"
double f(double x)
{double f;
f=pow(x, 3)-x+exp(-x);
return f;
}
void main()
{
const double e=0.00001, d=e/10;
const long Fn=50000; //N > (b-a)/(2*e)
long i, fnext, fpred, F, N;
double x1,x2, y1,y2, a=0, b=1;
cout<<"Method chisel Fibonachchi"<<endl<<endl;
//vychislyaem chisla vbbonachi
fpred=1; fnext=1; //f[0], f[1]
F=0; N=2;
while (F<Fn)
{F=fnext+fpred; //f[i]=[i-1]+f[i-2]
N++;
if (F<Fn)
{fpred=fnext; //[f[i-1] -> f[i-2]
fnext=F; //f[i] -> f[i-1]
}
}
/*fpred=f[n-2] , fnext=f[n-1], F=f[n] */
cout<<"Kol-vo chisel Fibonachchi: "<<N<<endl;
//vychislyaem ishodnye tochki