PROGRAM 01 Object: Write a C++ Source Code to find real root of a nonlinear function ‘ y f x ’ of a single variable using Bisection Method. Requirement: PC with C++ Compiler. Theory: Bisection method is an iterative method to find at least one real root of a nonlinear function y f x in a given interval. Mean Value Theorem can be used to be certain about existence of at least one real root of y f x in the interval. It falls under the category of closed methods. In addition to this, its rate of convergence is slow but guaranteed and it is also easy to program. One can find number of iterations in bisection method required to meet stopping criterion priori. Algorithm: 1. It requires two starting real numbers i.e. a and b. 2. If f a f b 0 , then find x1 called new iterate using average of a and b as: x1
3. Evaluate f x1 :
ab 2
i.
If f x1 0 then x1 is said to be root of y f x .
ii.
If f x1 0 then there are two possibilities as given below: a. If f a f x1 0 , compute the new iterate x2 a, x1 using a x1 2 b. If f x1 f b 0 , compute the new iterate x2 x1 , b using x2
x1 b 2 4. Repeat the entire procedure until stopping criterion is met. x2
Source Code: // To find root of y f x using Bisection Method. // f x 3x sin x e x on [0 1]; error tolerance =2% #include
#include #include #include #include using namespace std; int main( ) { float a,b,xn,xo=a,et,error; cout<>a>>b>>et; int i=1; cout<et); cout<<"\n The approximate root containing "<