Wa0000.
Wa0000.
Wa0000.
wxmx 1 / 4
Practical 1: Bisection
method
Theory: The bisection method is used to find
the approximate root of a function. It
separates the interval and subdivides the
interval in which the root of the equation
lies. The principle behind this method is the
intermediate theorem for continuous functions.
Solution:
Bisection method.wxmx 2 / 4
(%i6) kill(all)$
'x0=x0:0.0$
'x1=x1:1.0$
n:10;
f(x):= x^3− 5 . x + 1;
if(float((f(x0)·f(x1))>0)) then
print("change values")
else
for i:1 thru n do
(a:(x0+x1)/2,if(f(a)=0.0) then
return(a) else /*return (a) may be used to exit explicitly
from the current block, while, for or do loop
bringing its argument */
if(f(a)·f(x1))>0
then x1:a /*interval is [x0,a]*/
else x0:a /*interval is [a,x1]*/,
print(i,"iteration gives ",a));
print("The root is", a)$
(%o3) 10
3
(%o4) f ( x ) := x − 5 . x + 1
1 iteration gives 0.5
2 iteration gives 0.25
3 iteration gives 0.125
4 iteration gives 0.1875
5 iteration gives 0.21875
6 iteration gives 0.203125
7 iteration gives 0.1953125
8 iteration gives 0.19921875
9 iteration gives 0.201171875
10 iteration gives 0.2021484375
(%o5) done
The root is 0.2021484375
Bisection method.wxmx 3 / 4
➔ wxplot2d(f(x),[x,0,1.0],[ylabel,"f(x)"]);
(%t7)
(%o7)
Solution:
(%i6) kill(all)$
'x0=x0:0.0$
'x1=x1:2.0$
n:6;
f(x):= x^2− 1;
if(float((f(x0)·f(x1))>0)) then
print("change values")
else
for i:1 thru n do
(a:(x0+x1)/2,if(f(a)=0.0) then
return(a) else
if(f(a)·f(x1))>0
then x1:a
else x0:a,print(i,"iteration gives ",a));
print("The root is", a)$
(%o3) 6
2
(%o4) f ( x ) := x − 1
(%o5) 1.0
The root is 1.0
Bisection method.wxmx 4 / 4
➔ wxplot2d(f(x),[x,0,2.0],[ylabel,"f(x)"]);
(%t8)
(%o8)