0% found this document useful (0 votes)
17 views2 pages

Bisection Method for Programmers

This document describes a bisection method algorithm to find the root of a function between two values. It takes in initial start values x1 and x2, evaluates the function f at those points, and iteratively calculates a midpoint x3 until the difference between f(x1) and f(x2) is less than the specified accuracy. It then outputs the calculated root value x3 to the specified number of decimal places.

Uploaded by

Denny Paat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Bisection Method for Programmers

This document describes a bisection method algorithm to find the root of a function between two values. It takes in initial start values x1 and x2, evaluates the function f at those points, and iteratively calculates a midpoint x3 until the difference between f(x1) and f(x2) is less than the specified accuracy. It then outputs the calculated root value x3 to the specified number of decimal places.

Uploaded by

Denny Paat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

BISECTION METHOD

program bisection_method;
var
x1,x2,x3:real;
acc:integer;

function f(t:real):real;
begin
f:=t*t*t-t-1;
{the required function goes here. in this case it's
f(x)= x^3 - x - 1 }
end;

begin
writeln('Bisection method');

writeln('enter the 1st start value: ');


readln(x1);
writeln('enter the 2nd start value: ');
readln(x2);
if (f(x1)*f(x2)>0) or (f(x1)=f(x2)) then
writeln('Invalid starting points')
else
begin
writeln('to how many decimal places? ');
readln(acc);
if f(x1)=0 then begin x2:=x1;x3:=x1;end;
if f(x2)=0 then begin x1:=x2;x3:=x2;end;
while abs(f(x1)-f(x2))>1/exp(acc*(ln(10))) do
begin
x3:=(x1+x2)/2;
if f(x3)*f(x2)>=0 then x2:=x3;
if f(x3)*f(x1)>=0 then x1:=x3;
end;
writeln('The answer is: ',x3:5:acc+1);
end;

readln;
end.
Output Bisection method

Bisection method

enter the 1st start value:

0.4

enter the 2nd start value:

to how many decimal places?

The answer is: 1.3247

You might also like