Professional Documents
Culture Documents
Method
Q1) Find the root of the function f (x) = x3 -5x+1.Perform 5 iterations of Newton Raphson Method
to find the root of the function starting with the initial approximation 0.5
f[x_] := x3 - 5 x + 1;
Plot[f[x], {x, - 4, 4}]
15
10
-4 -2 2 4
-5
-10
-15
k = 0.5; (*k = p0 *)
n = 5;
Iff '[k] ⩵ 0, Print["We cannot continue with the Newton Raphson method"],
i = 1;
f[k]
p = k- ;
f '[k]
OutputDetails = {{i, k}};
f[k]
Whilei < n, p = k - ; k = p; i ++;
f '[k]
OutputDetails = Append[OutputDetails, {i, k}];
(* Combining the output details with the headings of the table*)
Print[NumberForm [N[TableForm[OutputDetails, TableHeadings → {None, {"i", "k i "}}]], 8]];
i ki
1. 0.5
2. 0.17647059
3. 0.20156807
4. 0.20163968
5. 0.20163968
f[x_] := x3 - 17;
Plot[f[x], {x, - 4, 4}]
40
20
-4 -2 2 4
-20
-40
-60
-80
k = 2; (*k = p0 *)
n = 5;
Iff '[k] ⩵ 0, Print["We cannot continue with the Newton Raphson method"],
i = 1;
f[k]
p = k- ;
f '[k]
OutputDetails = {{i, k}};
f[k]
Whilei < n, p = k - ; k = p; i ++;
f '[k]
OutputDetails = Append[OutputDetails, {i, k}];
(* Combining the output details with the headings of the table*)
Print[NumberForm [N[TableForm[OutputDetails, TableHeadings → {None, {"i", "k i "}}]], 8]];
i ki
1. 2.
2. 2.75
3. 2.5826446
4. 2.5713315
5. 2.5712816
Q3) f(x)=e-x - x
practical2.nb 3
f[x_] := Exp[- x] - x;
Plot[f[x], {x, - 4, 4}]
30
20
10
-4 -2 2 4
k = 0; (*k = p0 *)
n = 5;
Iff '[k] ⩵ 0, Print["We cannot continue with the Newton Raphson method"],
i = 1;
f[k]
p = k- ;
f '[k]
OutputDetails = {{i, k}};
f[k]
Whilei < n, p = k - ; k = p; i ++;
f '[k]
OutputDetails = Append[OutputDetails, {i, k}];
(* Combining the output details with the headings of the table*)
Print[NumberForm [N[TableForm[OutputDetails, TableHeadings → {None, {"i", "k i "}}]], 8]];
i ki
1. 0.
2. 0.5
3. 0.566311
4. 0.56714317
5. 0.56714329
Q3) Cos x -x
4 practical2.nb
f[x_] := Cos[x] - x;
Plot[f[x], {x, - 4, 4}]
-4 -2 2 4
-2
-4
k = 0; (*k = p0 *)
n = 5;
Iff '[k] ⩵ 0, Print["We cannot continue with the Newton Raphson method"],
i = 1;
f[k]
p = k- ;
f '[k]
OutputDetails = {{i, k}};
f[k]
Whilei < n, p = k - ; k = p; i ++;
f '[k]
OutputDetails = Append[OutputDetails, {i, k}];
(* Combining the output details with the headings of the table*)
Print[NumberForm [N[TableForm[OutputDetails, TableHeadings → {None, {"i", "k i "}}]], 8]];
i ki
1. 0.
2. 1.
3. 0.75036387
4. 0.73911289
5. 0.73908513
Q4) f(x)=Ln(1+x)-x
g[x_] := Log[1 + x] - x;
Plot[g[x], {x, - 0.005, 0.005}]
practical2.nb 5
-2. × 10-6
-4. × 10-6
-6. × 10-6
-8. × 10-6
-0.000010
-0.000012
k = 0.5; (*k = p0 *)
n = 20;
Ifg '[k] ⩵ 0, Print["We cannot continue with the Newton Raphson method"],
i = 1;
g[k]
p = k- ;
g '[k]
OutputDetails = {{i, k}};
g[k]
Whilei < n, p = k - ; k = p; i ++;
g '[k]
OutputDetails = Append[OutputDetails, {i, k}];
(* Combining the output details with the headings of the table*)
Print[NumberForm [N[TableForm[OutputDetails, TableHeadings → {None, {"i", "k i "}}]], 8]];
i ki
1. 0.5
2. 0.21639532
3. 0.10114167
4. 0.048947214
5. 0.024083797
6. 0.011946374
7. 0.0059495423
8. 0.0029688891
9. 0.0014829777
10. 0.00074112258
11. 0.00037046978
12. 0.00018521202
13. 0.000092600292
14. 0.000046298716
15. 0.000023148999
16. 0.000011574415
17. 5.7871848 × 10-6
18. 2.8935948 × 10-6
19. 1.4468173 × 10-6
20. 7.2343992 × 10-7
Q6)
6 practical2.nb
f[x_] := x3 + 2 x2 - 3 x - 1 ;
Plot[f[x], {x, - 4, 4}]
40
30
20
10
-4 -2 2 4
-10
-20
k = 0; (*k = p0 *)
n = 5;
Iff '[k] ⩵ 0, Print["We cannot continue with the Newton Raphson method"],
i = 1;
f[k]
p = k- ;
f '[k]
OutputDetails = {{i, k}};
f[k]
Whilei < n, p = k - ; k = p; i ++;
f '[k]
OutputDetails = Append[OutputDetails, {i, k}];
(* Combining the output details with the headings of the table*)
Print[NumberForm [N[TableForm[OutputDetails, TableHeadings → {None, {"i", "k i "}}]], 8]];
i ki
1. 0.
2. -0.33333333
3. -0.28703704
4. -0.28646216
5. -0.28646207