[go: up one dir, main page]

0% found this document useful (0 votes)
30 views1 page

Bisectionmethod

The document outlines a MATLAB implementation of the Bisection method to find the root of the function f(x) = exp(x) - 2*x - 2. It prompts the user for initial guesses and accuracy, checks for valid input, and iteratively narrows down the root until the desired accuracy is achieved. The final output shows the calculated root as approximately 1.678711.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views1 page

Bisectionmethod

The document outlines a MATLAB implementation of the Bisection method to find the root of the function f(x) = exp(x) - 2*x - 2. It prompts the user for initial guesses and accuracy, checks for valid input, and iteratively narrows down the root until the desired accuracy is achieved. The final output shows the calculated root as approximately 1.678711.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Name = Avhad Anita Navanath

Roll no. = 132


Bisection method

clc;
clear all;
f=@(x) ( exp ( x ) - 2*x -2 ) ;
x1 = input ('\n enter x1 = ') ;
x2 = input ( '\n enter x2 = ' ) ;
acc = input ( '\n enter accuracy = ' ) ;
y1 = f( x1 ) ;
y2 = f ( x2 ) ;
fprintf ( '\n y1 = %f' ,y1) ;
fprintf ( '\n y2 = %f' ,y2) ;
while ( y1*y2 ) > 0
fprintf ( '\n intial guess is wrong') ;
x1 = input ('\n enter x1 = ') ;
x2 = input ( '\n enter x2 = ' ) ;
y1 = f( x1 ) ;
y2 = f ( x2 ) ;
end
while ( abs( x2-x1 ) > acc )
x3 = ( x1 + x2 ) / 2 ;
y3 = f( x3 );
if ( y1 * y3) < 0
x2 = x3 ;
y2 = y3 ;
else
x1 = x3 ;
y1 = y3 ;
end
end
fprintf ( '\n root is = %f' , x3 ) ;
-------------------------------------------------------------
Solver
>> x0 = [ 1 , 2 ] ;
>> x = fzero(('exp(x)-2*x-2') , x0 )

x =

1.6783
----------------------------------------------------------------
Solution

enter x1 = 0
enter x2 = 1
enter accuracy = 0.001
y1 = -1.000000
y2 = -1.281718
intial guess is wrong
enter x1 = 1
enter x2 = 2

root is = 1.678711

You might also like