Added preface: . What could go wrong with the algorithm as presented, even if all data types were suitable?
Unlike the bisection method, pure regulatory falsification will not force the interval length to be zero. If a monotone and convex function is used, then the iteration stops when only one side of the interval with geometric convergence changes.
, c . , c , , .
, . . - .
c = |f(b)|/(|f(a)|+|f(b)|) * a + |f(a)|/(|f(a)|+|f(b)|) * b
- f (a) f (b) . b , f (b), .. .
Illulais regula falsi ( ). 2.2e-6 6e-7 6 .
#include<math.h>
#include<stdio.h>
float fonc(float x)
{
return (2*x*x-1)*x-2;
}
int main(void)
{
float eps=1e-6;
int i=0;
float a=1, fa = fonc(a);
float b=2, fb = fonc(b);
printf("\na=%10.7f b=%10.7f fa=%10.7f fb=%10.7f\n------\n",a,b, fa,fb);
if(signbit(fb)==signbit(fa)) {
printf("Attention, les valeurs initiales de 'fonc' n'ont pas de signe opposeés!\n");
}
do
{
float c=(a*fb-b*fa)/(fb-fa), fc = fonc(c);
if( signbit(fc)!=signbit(fa) )
{
b=a; fb=fa;
a=c; fa=fc;
}
else
{
a=c; fa=fc;
fb *= 0.5;
}
i++;
printf("\na=c=%10.7f b=%10.7f fa=fc=%10.7f fb=%10.7f",c,b, fc,fb);
if(fabs(fc)<eps) break;
}
while(fabs(b-a)>eps);
printf("\nle nombre d'itération %d\n",i);
return 0;
}
a= 1.0000000 b= 2.0000000 fa=-1.0000000 fb=12.0000000
------
a=c= 1.0769231 b= 2.0000000 fa=fc=-0.5789710 fb= 6.0000000
a=c= 1.1581569 b= 2.0000000 fa=fc=-0.0512219 fb= 3.0000000
a=c= 1.1722891 b= 1.1581569 fa=fc= 0.0497752 fb=-0.0512219
a=c= 1.1653242 b= 1.1722891 fa=fc=-0.0003491 fb= 0.0497752
a=c= 1.1653727 b= 1.1722891 fa=fc=-0.0000022 fb= 0.0248876
a=c= 1.1653733 b= 1.1653727 fa=fc= 0.0000020 fb=-0.0000022
le nombre d'itération 6