Numerical Prac4c(Secant Method)
Numerical Prac4c(Secant Method)
x1=2
Nmax20
1
epsilon=
1 000 000
f[x]:=Cos[x]
root is :1.5708
1.0
0.5
-1 1 2 3
-0.5
-1.0
Ques. 2
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_] := x3 - 5 x + 1;
Print["f[x]:=", f[x]];
Fori = 1, 1 ⩽ Nmax, i ++,
x2 =
Nx1 - f[x] /. x -> x1 * x1 - x0 f[x] /. x -> x1 - f[x] /. x -> x0;
If[Abs[x1 - x2] < eps, Return[x2], x0 = x1; x1 = x2];
Print["In", i, "th Number of iterations the root is :", x2];
Print["estimated error is :", Abs[x1 - x0]];
Print["root is :", x1];
Print["estimated error is :", Abs[x2 - x1]];
Plot[f[x], {x, - 1, 3}]
NUMERICAL PRAC4c(SECANT METHOD).nb 3
x0=1
x1=2
Nmax20
1
epsilon=
1 000 000
f[x]:=1 - 5 x + x3
root is :2.12842
10
-1 1 2 3
4 NUMERICAL PRAC4c(SECANT METHOD).nb
Ques. 3
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]];
Fori = 1, 1 ⩽ Nmax, i ++,
x2 =
Nx1 - f[x] /. x -> x1 * x1 - x0 f[x] /. x -> x1 - f[x] /. x -> x0;
If[Abs[x1 - x2] < eps, Return[x2], x0 = x1; x1 = x2];
Print["In", i, "th Number of iterations the root is :", x2];
Print["estimated error is :", Abs[x1 - x0]];
Print["root is :", x1];
Print["estimated error is :", Abs[x2 - x1]];
Plot[f[x], {x, - 1, 3}]
x0=1
x1=2
Nmax20
1
epsilon=
1 000 000
f[x]:=-ⅇx x + Cos[x]
Return[0.517757]
root is :0.517757
-1 1 2 3
-10
-20
-30
-40
-50
-60