0% found this document useful (0 votes)
53 views5 pages

Harshit Prac2 (B)

The document contains 3 numerical problems solved using the Regula Falsi method to find the root of various functions. The first problem finds the root of f(x)=Cos(x) to be approximately 1.570796327 within 0.000182248 iterations. The second problem cannot find a root for the given initial values due to the IVP not being satisfied. The third problem finds no root for f(x)=-ex x + Cos(x) within the given bounds.

Uploaded by

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

Harshit Prac2 (B)

The document contains 3 numerical problems solved using the Regula Falsi method to find the root of various functions. The first problem finds the root of f(x)=Cos(x) to be approximately 1.570796327 within 0.000182248 iterations. The second problem cannot find a root for the given initial values due to the IVP not being satisfied. The third problem finds no root for f(x)=-ex x + Cos(x) within the given bounds.

Uploaded by

Jasmi Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Practical 2 (b) :

- Regula Falsi Method


Harshit Sahu
BSc (H) Computer Science
Sem - IV 20 211 414
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 Harshit 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


Harshit 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
4 Harshit Prac2(b).nb

Question 2 :

In[26]:= 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_] := x ^ 3 - 5 x + 1;
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]:=1 - 5 x + x3

These values do not satisfy the IVP so change the values.

10

Out[36]= 5

-1 1 2 3
Harshit Prac2(b).nb 5

Question 3 :

In[37]:= 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] - x * Exp[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]:=-ⅇx x + Cos[x]

These values do not satisfy the IVP so change the values.

-1 1 2 3

-10

-20

Out[47]= -30

-40

-50

-60

You might also like