False Position Algorithm
1. Start
2. Read values of x0, x1 and e
*Here x0 and x1 are the two initial guesses
e is the degree of accuracy or the absolute error i.e. the stopping
criteria*
3. Computer function values f(x0) and f(x1)
4. Check whether the product of f(x0) and f(x1) is negative or not.
If it is positive take another initial guesses.
If it is negative then goto step 5.
5. Determine:
x = [x0*f(x1) – x1*f(x0)] / (f(x1) – f(x0))
6. Check whether the product of f(x1) and f(x) is negative or not.
If it is negative, then assign x0 = x;
If it is positive, assign x1 = x;
7. Check whether the value of f(x) is greater than 0.00001 or not.
If yes, goto step 5.
If no, goto step 8.
*Here the value 0.00001 is the desired degree of accuracy, and
hence the stopping criteria.*
8. Display the root as x.
9. Stop
Example:
Solve for the root in the interval [1,2] by Regula-Falsi
method:
Solution: Since , we go ahead in finding the root of
given function f(x) in [1,2].
Set .
set
, proceed with iteration.
Iteration details are provide below in a tabular form:
Regula Falsi
Method
Iteration
no.
0 1.0000000000 2.0000000000 1.4782608747 -2.2348976135
1 1.4782608747 2.0000000000 1.6198574305 -0.5488323569
2 1.6198574305 2.0000000000 1.6517157555 -0.1169833690
3 1.6517157555 2.0000000000 1.6583764553 -0.0241659321
4 1.6583764553 2.0000000000 1.6597468853 -0.0049594725
5 1.6597468853 2.0000000000 1.6600278616 -0.0010169938
6 1.6600278616 2.0000000000 1.6600854397 -0.0002089010
7 1.6600854397 2.0000000000 1.6600972414 -0.0000432589
8 1.6600972414 2.0000000000 1.6600997448 -0.0000081223
Example:
Solve for the root in the interval [0.5,1.5] by Regula
Falsi method.
Regula Falsi
Method
Iteration
no.
0 0.5000000000 1.5000000000 0.8773435354 2.1035263538
1 0.5000000000 0.8773435354 0.7222673893 0.2828366458
2 0.5000000000 0.7222673893 0.7032044530 0.0251714624
3 0.5000000000 0.7032044530 0.7015219927 0.0021148270
4 0.5000000000 0.7015219927 0.7013807297 0.0001767781
5 0.5000000000 0.7013807297 0.7013689280 0.0000148928
6 0.5000000000 0.7013689280 0.7013679147 0.0000009526
Newton Raphson Algorithm
1. Start
2. Read x, e, n, d
*x is the initial guess
e is the absolute error i.e the desired degree of accuracy
n is for operating loop
d is for checking slope*
3. Do for i =1 to n in step of 2
4. f = f(x)
5. f1 = f'(x)
6. If ( [f1] < d), then display too small slope and goto 11.
*[ ] is used as modulus sign*
7. x1 = x – f/f1
8. If ( [(x1 – x)/x1] < e ), the display the root as x1 and goto 11.
*[ ] is used as modulus sign*
9. x = x1 and end loop
10. Display method does not converge due to oscillation.
11. Stop
Example:
Solve for the root in [1,2] by Newton Raphson
method.
Solution:
Given
Take and
Since,
Therefore repeat the process.
Results are tabulated below:
Newton Rahpson Method
Iteration no.
0 2.0000000000 1.7209302187 0.8910911679
1 1.7209302187 1.6625729799 0.0347661413
2 1.6625729799 1.6601046324 0.0000604780
3 1.6601046324 1.6601003408 0.0000002435
Example:
Solve in [0.5,1.5] for the root by Newton-Raphson
method.
Solution: Given
Say,
The results are tabulated below:
Newton Raphson Method
Iteration no.
0 0.5000000000 0.6934901476 0.1086351126
1 0.6934901476 0.7013291121 0.0005313741
2 0.7013291121 0.7013678551 0.0000003363
False Position
syms x;
f=inline(cos(x)+ 2*sin(x) + x^2);
a=input('Give the value of lower x: ');
b=input('Give the value of upper x: ');
e=input('Give the value of tolerance: ');
c=(a-(f(a)*(b-a))/(f(b)-f(a)));
itr=1;
while (abs(f(c))>e)
if(f(a)*f1(c)<0)
b=c;
else
a=c;
end
c=(a-(f(a)*(b-a))/(f(b)-f(a)));
itr=itr+1;
end
c
itr_no=itr
Newton Raphson
syms x;
f=inline(cos(x)+ 2*sin(x) + x^2);
z=diff(f(x));
f1=inline(z);
x0=0;
x=x0;
for u=1:100
y=x;
x=y-[f(x)/f1(x)];
if x==y
break
end
end
x
u