0% found this document useful (0 votes)
4 views

Bisection methods

.

Uploaded by

mohitsangwan1133
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Bisection methods

.

Uploaded by

mohitsangwan1133
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

~~~-, Mahile o;P/lc.oi;__an _ ex xc/;,o,d .

-)

I t, a

q1ven

7AiA toe I-hod iii


., a
rco e+hod , m ethad 1 &er / OftJ
oJUl d tne-lli ocl,

' A+ @c/2 A1£fJ-- d!Yi'J~ -tke- inferv&. l ,nio _ lrilLLflL _ _


/c= u+b/2.
, [ ,'fb e?s
_a.ri d jt'nd tJ-.e value pc:)_.,- ----
.j:Jc) = o +A en__J,Qe _ &11_ --1fkip _ _d tft~ a<l__
c_ w ,ti be ,1Mj JiJt_ . _ 'tPt2"L_ _ _ _ _ _ _ _ _ _ __
· ~JoiJL,--fi-o. ) _ DJJJ _/:Jc}_ bav<!! c:yJf-olJie ~ ~ --
j {b-}---4~ cl /({J h~v e_ -°f-fkMt'±L _Jfjr,j _.. ___
-

• fot dhe_ f'°J-A± _ QM e _ Je f a ~ C I


dJe -A~

,, (oJJii__>ql-Lf:----dJ:i.e .Mep_). '!Jc,{ n _ lm -f if _ rJou__c±f!_or}yei_ _


o.iJJ./ • - - - - - - - --- -
i!( ')U ([
/Ifie!> Ac,mt? /4.1 ff;} ife ~cdiaM --IA e va_/y_f' f-
:j (q) and /GJ ,uf/1 _fo1i vqre 7&od12 i/°Y _
Jo cd / ctr flie_
Cc.n dfj if U, ,/1,e_
-- - ·
____ __ p°fjnam1d • -
----- - - - - - --
-- - -- - - -- - - - - - -
1 include <iostrear<l >
2 #include <r<lath.h >
3 #include <ior<lanip>
4
S using nar<lespace std;
6
7 double f(double);
8 double df(double);
9
10 double f(double a, double b,
double c, double d, double x)
11 {
12 double 4 =a* x * x * x + b * x
* X + C * X + d;
13 return 4;
14 }
1S double df(double a, double b,
double c, double d, double x)
16 {
17 double 2 = 3 *a* x * x + 2 *
b * X + C;
18 return 2 ;
19 }
20
2 1 int r<lain()
22 {
23 double a, b, c, d, x0, x 1, e, h, i;

24
25 e = 0.000 1;
26 i = 0;
27
28 cout << " Please Enter The
Value Of a:";
29 cin » a;
30
31 cout << " Please Enter The
Value Of b: ";
32 cin » b;
33
34 cout << " Please Enter The
Value Of c: ";
35 cin » c;
36
37 cout << " Please Enter The
Value Of d: ";
38 cin » d;
39
40 cout << " Please Enter The
Value Of The Initial Guess At
The Root:"
41 cin » x0;
42
43 h = f(a, b, c, d, x0) / df(a, b, c,
d, x0);
44
45 while (fabs(h) >= e)
46 {
47 x 1 = x0 - h;
48 h = f( a, b, C, d, x 1) / df(a, b,
C, d, x 1);
49 x0= x l;
so i++;
51 }
S2 cout << " The Root Of The
Equation Is : " << x0 << "\n
And The No. Of Iterations Is:"
<< i;
53 }
P1eose Enter The Vo1ue Of o :
1
P1eose Enter The Vo1ue Of b :
1
P1eose Enter The Vo1ue Of c :
3
P1eose Enter The Vo1ue Of d :
4
P1eose Enter The Vo1ue Of The
In itio 1Guess Rt The Root : 2
The Root Of The Equotion Is :
-1.22249
find The No. Of Iterotions Is
:8
[ProgrofY1 finished] I
1 include <iostream >
2 #include <conio.h>
3 #include <math.h >
4 #define f(x) (x - cos(x))
5 using namespace std;
6 int main()
7 {
8 float x 1, x2, xm, e, i = 0, fx 1,
fx2;
9 cout << "\nFor the function
x-cosx\n";
10 cout << "\nEnter accuracy
required : ";
11 cin >> e;
12 // Condition : x2 >X 1
13 cout << "Enter value of x 1 :

14 cin » x 1;
15 cout << "Enter value of x2 :

16 cin » x2;
17 fx 1 = f(x 1);
18 fx 2 = f(x2);
19 while (fx 1 * fx2 > 0)
20 {
21 cout << "\n Tr4 Again with
better guess\n";
22 cout << "\nEnter value of
X 1 : ";
23 cin >> x 1;
24 cout « "Enter value of
x2: ";
25 cin >> x2;
26 fx 1 = f(x 1);
27 fx2 = f(x2);
28 }
29 cout << "Value of f(x) at x 1
" << fx 1 << "\n";
30 cout << "Value at f(x) at x2
" << fx2 << "\n";
31 while (x2 - x 1 > e)
32 {
33 xm = (x 1 + x2) / 2;
34 if (f(xm) == 0)
35 {
36 break;
37 }
38 else if (f(xm) < 0)
39 {
40 X 1 = Xr<l;
41 }
42 else
43 {
44 X2 = Xr<l;
45 }
46 i+= l;
47 }
48 cout « "Root is->" « xm;
49 cout << "\nNumber of
iterations : " << i;
so }
For the function x-cosx

Enter occurocy required : 0.00


01
Enter vo1ue of x 1 : 0
Enter vo1ue of x2 : 3
Vo1ue of f(x) ot x 1 : -1
Vo1ue ot f(x) ot x2 : 3.98999
Root is->0.7391 OS
NurY1ber of iterotions : 1S
[Pro9rorY1 finished] I

You might also like