Bipartite Algorithm Thought: first, determine the root interval, divide the second-class interval, and gradually narrow down the root interval by judging the symbol F (x) until the root interval is small enough, the approximate values that meet the precision requirements can be obtained. Flowchart:
Instance:
Evaluate f (x) = x ^ 3-x-1 to a solid root in [1, 1.5], so that the error cannot exceed 0.005.
ProgramThe implementation is as follows (C ++ ):
# Include <iostream>
# Include <math. h>
Using Namespace STD;
Float Partition ( Float X)
{
Return X-X- 1 ;
}
Int Main ()
{
Float A, B, C, X;
Cin> A> B> C;
While (FABS (B-a)> = C)
{
X = (a + B )/ 2 ;
If (Random (a) * random (x) < 0 )
{
B = X;
}
Else
{
A = X;
}
}
Cout < " The values that meet the requirements are: " <X <Endl;
Return 0 ;
}
Exercise: Obtain the root of the equation f (x) = x ^ 3-2x-5 in the interval [2, 3] by using the bipartite method.