Bisection Method: Muataz Abdulsmad
Bisection Method: Muataz Abdulsmad
Bisection Method: Muataz Abdulsmad
Faculty of Engineering
Department of Computer Engineering
Numerical Analysis
Bisection Method
And then process is repeated until we find the root within desired
accuracy.
Muataz Abdulsmad
Bisection Method Program in C++ :
#include<iostream>
using namespace std;
int main()
{
double a,b;
a=-10;
b=20;
cout<<"The function used is x^3-2x^2+3\n";
cout<<"a = "<<a<<endl;
cout<<"b = "<<b<<endl;
bisection(a,b);
cout<<"\n";
cout<<"Accurate Root calculated is
="<<c<<endl;
return 0;
}
Output :
a = -10.000000
b = 20.000000
Root = 5.000000
Root = -2.500000
Root = 1.250000
Root = -0.625000
Root = -1.562500
Root = -1.093750
Root = -0.859375
Root = -0.976563
Root = -1.035156
Root = -1.005859
Root = -0.991211
Root = -0.998535
Accurate Root calculated is = -0.998535
Newton-Raphson Method
Muataz Abdulsmad
f ( x 0)
x 1=x 0− where x0 is the first approximate value, then,
f ' (x 0)
f ( x 1)
x 2=x 1− and so on.
f ' (x 1)
So if xn is the current estimated value, the next approximation xn+1 is given
by
f ( xn )
xn+1= xn− ' ( )
f xn
double func(double x)
{
return x*x*x - 2*x*x +3;
}
double derivFunc(double x)
{
return 3*x*x - 4*x;
}
while(fabs(x1-x)>=EPSILON)
{
x=x1;
x1=x-func(x)/derivFunc(x);
}
Muataz Abdulsmad
cout << "The value of the root is : " << x1;
}
int main()
{
double x0 =-10; // Initial values assumed
newtonRaphson(x0);
return 0;
}
Output:
Secant Method
Secant Method is open method and starts with two initial guesses for finding
real root of non-linear equations.in Secant method if x0 and x1 are initial
guesses then next approximated root x2 is obtained by following formula:
x2 = x1 - (x1-x0) * f(x1) / ( f(x1) - f(x0) )
int main()
{
double x0=2,x1=4; // Initial values assumed
secant(x0,x1);
return 0;
}
Output:
The value of the root is : 3.44949
If x0 is initial guess then next approximated root in this method is obtaine by:
x1 = g(x0)
and similarly, next to next approximated root is obtained by using value
of x1 i.e.
Muataz Abdulsmad
x2 = g(x1)
and the process is repeated until we get root within desired accuracy.
Note: While expressing f(x)=0 to x = g(x) we can have many different forms.
For convergence, following criteraia must be satisfied.
|g'(x)|< 1
Muataz Abdulsmad
int main()
{
double x0=1; // Initial values assumed
fixed_point(x0);
return 0;
}
Output:
The value of the root is : 1.99984
Muataz Abdulsmad