Applications
© The scientific sentence. 2010
|
false point method
1. The method:
The process for this method is the same as the bisection, except
in lieu of taking the middle point, we consider the root of the
line joining the two related points, instead.
The steps are:
Step 1:
Choose xl and xu, and make the test: f(xl)*f(xu) < 0.
If yes, we continue, otherwise, no roots for this function.
Step 2 :
Find the intersection of the line connecting the two points (xl,f(xl)),
and (xu,f(xu)) and the x-axis, which is:
xr = xu - f(xu)(xu - xl)/(f(xu) - f(xl))
Step 3:
Determine the new bracket:
If f(xr)*f(xl) < 0 , then xu = xr
else xl = xr
Step 4: Repeat the iteration to become closer to the true solution.
2. Example in clanguage
// flase_point.c program
#include
#include
#include
// false point method
//--------------------------
double g = 9.81;
float y = 100, t0 = 2.00, t1 = 6.00;
//float E;
float f(float x)
{
//return cos(x);
//return (x/16.0 - 1/8.0);
return y - (g/2)*x*x;
}
int main()
{
float l = t0, u = t1, r[21];
int i,n = 20;
if(f(l)*f(u) <0)
{
for(i=1;i<=n;i++)
{
r[i]= u - f(u)*(u -l)/(f(u) - f(l));
if(f(l)*f(r[i])<0)
{
u=r[i];
}
if(f(l)*f(r[i])>0)
{
l=r[i];
}
printf("\t %1.6f\n",r[i]);
}
printf("The solution is : %1.2f\n",r[n]);
printf("The error: %1.6f\n",100*(r[n] - r[n-1])/r[n]);
}
else
{
printf("There is no roots in this range .\n");
}
return 0;
}
Compiled and executed yields:
>gcc -msse2 -O3 -march=pentium4 -malign-double -funroll-loops -pipe
-fomit-frame-pointer -W -Wall -o "false_point.exe" "false_point.c"
>Exit code: 0
>false_point
4.048420
4.446259
4.505433
4.513851
4.515041
4.515209
4.515233
4.515236
4.515236
4.515236
4.515236
4.515236
4.515236
4.515236
4.515236
4.515236
4.515236
4.515236
4.515236
4.515236
The solution is : 4.52
The error: 0.000000
>Exit code: 0
|
|
|