You are on page 1of 3

Practical 2 (b) :

- Regula Falsi Method


Aakib Khan
BSc (H) Computer Science
Sem - IV 20 211 403
Question 1 :

x0 = Input["Enter first guess:"];


x1 = Input["Enter second guess:"];
Nmax = Input["Enter maximum number of iterations:"];
eps = Input["Enter the value of convergence parameter:"];
Print["x0=", x0];
Print["x1=", x1];
Print["Nmax=", Nmax];
Print["epsilon=", eps];
f[x_] := Cos[x];
Print["f[x]:=", f[x]]; IfN[f[x0] * f[x1]] > 0,
Print["These values do not satisfy the IVP so change the values."],
Fori = 1, i ≤ Nmax, i ++, a = Nx1 - f[x1] * x1 - x0  f[x1] - f[x0], 16;
IfAbsx1 - x0  2 < eps,
Return[N[a, 16]], Print[i, "th iteration value is:", N[a, 16]];
Print["In ", i, "th number of iterations the root is:", x2];
Print["Estimated error is:", N[x1 - x0, 16]];
If[f[a] * f[x1] > 0, x1 = a, x0 = a];
Print["Root is:", N[a, 16]];
Print["Estimated error is:", N[x1 - x0, 16]];
Plot[f[x], {x, - 1, 3}]
x0=1

x1=2

Nmax=20
1
epsilon=
1 000 000
f[x]:=Cos[x]

1th iteration value is:1.564904375891578

In 1th number of iterations the root is:x2


2 Aakib Prac2(b).nb

Estimated error is:1.000000000000000

2th iteration value is:1.570978574535018

In 2th number of iterations the root is:x2

Estimated error is:0.435095624108422

3th iteration value is:1.570796325773051

In 3th number of iterations the root is:x2

Estimated error is:0.006074198643440

4th iteration value is:1.57079632679490

In 4th number of iterations the root is:x2

Estimated error is:0.000182248761967

5th iteration value is:1.57079632679490

In 5th number of iterations the root is:x2

Estimated error is:0.00018224774012

6th iteration value is:1.5707963267949

In 6th number of iterations the root is:x2

Estimated error is:0.00018224774012

7th iteration value is:1.5707963267949

In 7th number of iterations the root is:x2

Estimated error is:0.0001822477401

8th iteration value is:1.5707963267949

In 8th number of iterations the root is:x2

Estimated error is:0.0001822477401

9th iteration value is:1.570796326795

In 9th number of iterations the root is:x2

Estimated error is:0.0001822477401

10th iteration value is:1.570796326795

In 10th number of iterations the root is:x2

Estimated error is:0.000182247740

11th iteration value is:1.570796326795

In 11th number of iterations the root is:x2

Estimated error is:0.000182247740

12th iteration value is:1.570796326795

In 12th number of iterations the root is:x2

Estimated error is:0.000182247740

13th iteration value is:1.57079632679

In 13th number of iterations the root is:x2


Aakib Prac2(b).nb 3

Estimated error is:0.000182247740

14th iteration value is:1.57079632679

In 14th number of iterations the root is:x2

Estimated error is:0.00018224774

15th iteration value is:1.57079632679

In 15th number of iterations the root is:x2

Estimated error is:0.00018224774

16th iteration value is:1.5707963268

In 16th number of iterations the root is:x2

Estimated error is:0.00018224774

17th iteration value is:1.5707963268

In 17th number of iterations the root is:x2

Estimated error is:0.0001822477

18th iteration value is:1.5707963268

In 18th number of iterations the root is:x2

Estimated error is:0.0001822477

19th iteration value is:1.570796327

In 19th number of iterations the root is:x2

Estimated error is:0.0001822477

20th iteration value is:1.570796327

In 20th number of iterations the root is:x2

Estimated error is:0.000182248

Root is:1.570796327

Estimated error is:0.000182248

1.0

0.5

-1 1 2 3

-0.5

-1.0

You might also like