Numerical Lab - Tanmoy
Numerical Lab - Tanmoy
𝑦 = 𝑓 (𝑥)
1st approximated 𝐵(𝑏 , 𝑓 ( 𝑏 ) ) Here, is negative.
root So, the actual root, lies between
Now, replace the value of ‘a’ such that
𝑎 +𝑏 𝑓 (𝑏)
𝑥1 =
2 Hence,
a 𝑥𝑟 𝑓 ( 𝑥 𝑟 )=0
𝑥
𝑓 (𝑥 1)
𝑓 (𝑎)
𝐶 (𝑥 1, 𝑓 (𝑥1 ))
𝐴(𝑎 , 𝑓 ( 𝑥 ) )
is negative
Concept of Bisection Method:
1st approximated
𝑦 = 𝑓 (𝑥) root
𝐵(𝑏 , 𝑓 ( 𝑏 ) ) Here, is positive.
So, the actual root, lies between
𝑎 +𝑏 𝐶 (𝑥 1, 𝑓 (𝑥1 )) Now, replace the value of ‘a’ such that
𝑥1 =
2
𝑓 (𝑏)
Hence,
𝑓 ( 𝑥 1)
a 𝑥𝑟
𝑥
𝑓 ( 𝑥 𝑟 )=0
𝑓 (𝑎)
𝐴(𝑎 , 𝑓 ( 𝑥 ) )
is positive
Bisection Method:
Working Rule:
1. Let be the given equation. Find two number ‘a’ and ‘b’ such that and . Alternately, we also can say that .
2. Find 1st approximate root by using the following formula of bisection method-
2.1 If < 0, The root lies between and . Now, . Hence, the 2nd approximate root is given by-
2.2 If 0, The root lies between and . Now, Hence, the 2nd approximate root is given by-
Calculate and repeat step 2.1 and 2.2 until achieving the required accuracy of the root.
Numerical Example: Find the root of the equation using bisection method correct up to 3 decimal points.
Solution:
Let,
Step 1: Find ‘a’ and ‘b’ such that and
So,
Step 2: Find the 1st approximated root using formula and calculate
==1.5
And f(x1)=1.53-1.5-1=15/8 which is positive
Step 3: As 0, The root lies between and . Now, Hence, b=1.5 and a=1. So, the 2nd approximate root will be
=1.25
Now, f(x2)= -19/64
Step 4: As 0, The root lies between and . Now, Hence, a=1.25 and b=1.5. So, the 2nd approximate root will be
=1.375
The same process is repeated and the successive approximations are
x4=1.3125, x5=1.34375, x6=1.328125
Sample MATLAB code for Bisection Method:
clc
clear all
f=input('please enter the equation=');
a=input('Please enter the value of a=');
b=input('Please enter the value of b=');
fprintf('f(a)=%.5f,f(b)=%.5f\n',f(a),f(b))
n=input('please enter how many times loop continue= ');
e=input('Enter tolerance=');
if f(a)*f(b)>0
disp('The root does not lie in the interval')
end
if f(a)*f(b)<0
for i=1:n
c=(a+b)/2;
if abs(a-c)<e || abs(b-c)<e
break
end
if f(a)*f(c)<0
b=c;
end
if f(a)*f(c)>0
a=c;
end
end
fprintf(' root x = %f\n',c)
end
Concept of False Position Method:
Slope of CA= Slope of CB
𝑦 = 𝑓 (𝑥)
𝐵(𝑏 , 𝑓 ( 𝑏 ) )
𝑓 (𝑏)
)¿
¿
, 0
, 0)
¿1
(𝐶 𝑥 ¿
¿2
a 𝑥𝑟 𝑓 ( 𝑥 𝑟 )= 0
𝑥¿
𝑥
𝐸(
2. Find 1st approximate root by using the following formula of bisection method-
2.1 If < 0, The root lies between and . Now, . Hence, the 2nd approximate root is given by-
2.2 If 0, The root lies between and . Now, Hence, the 2nd approximate root is given by-
Calculate and repeat step 2.1 and 2.2 until achieving the required accuracy of the root.
Numerical Example: Find out the root of the following function using False Position Method
Solve:
if f(a)*f(b)>0
disp('The root does not lie in the interval')
end
if f(a)*f(b)<0
for i=1:n
c=(a*f(b)-b*f(a))/(f(b)-f(a));
if abs(a-c)<e || abs(b-c)<e
break
end
if f(a)*f(c)<0
b=c;
end
if f(a)*f(c)>0
a=c;
end
end
fprintf(' root x = %f\n',c)
end
Concept of Newton-Raphson Method
y=f(x)
f(xo)
f(x1) Similarly,
xr
x 2 x1 xo x The generalized formula for Newton-Raphson
xo-x1
Method:
Newton-Raphson Method Working Rule:
1. Given, Find the initial approximate root such that is close to zero.
2. Find and .
3. First approximate root, can be found by the formula of Newton-Raphson method
5. Hence, the general formula of Newton-Raphson method is given by the following expression-
Numerical Example: Find the root of the equation using bisection method correct up to 3 decimal points.
Let, s
And
As the sign of f(3) is positive and
f(4) is negative, the root of the
Now, equation lies between 3 and 4 but
f(3) and f(4) >> 0
for i=1:n
x(i+1)=x(i)-(f(x(i))/df(x(i)));
if abs((x(i+1)-x(i)))<e
break
end
end
for i=1:n
X(i+1)=X(i)-(f(X(i))/dff(X(i)));
if abs((X(i+1)-X(i)))<e
break
end
end