Sunteți pe pagina 1din 2

Laboratorul nr : 2

Metoda coardelor

Array[c, 50];
f[x_] := 2 * x ^ 3 - 3 * x ^ 2 - 12 * x + 12;
a = - 3; b = - 2;
If[f[a] * f[b] < 0,
c[0] = a - f[a] * (b - a) / (f[b] - f[a]),
Print["nu este solutie"] Break[]]; Print[N[c[0]]];
If[f[a] * f[c[0]] < 0, b = c[0], a = c[0]];
If[f[a] * f[b] < 0,
c[1] = a - f[a] * (b - a) / (f[b] - f[a]),
Print["nu este solutie"] Break[]]; Print [N[c[1]]];
If[f[a] * f[c[0]] < 0, b = c[1], a = c[1]];
i = 2;
e = 0.0001;
While[Abs[c[i - 1] - c[i - 2]] > e, If[f[a] * f[b] < 0,
c[i] = a - f[a] * (b - a) / (f[b] - f[a]),
Print["nu este solutie"] Break[]];
If[f[a] * f[c[i]] < 0, b = c[i], a = c[i]];
Print[{N[c[i]], N[f[c[i]]]}, " ", i];
i ++];

- 2.19512

- 2.25664

{- 2.27464, 0.235795} 2

{- 2.27979, 0.0671171} 3

{- 2.28125, 0.0190408} 4

{- 2.28166, 0.00539667} 5

{- 2.28178, 0.00152915} 6

{- 2.28181, 0.000433252} 7

Plot[2 * x ^ 3 - 3 * x ^ 2 - 12 * x + 12, {x, - 3, 3}]


20

10

-3 -2 -1 1 2 3

-10

-20

-30
2 Lab2v5Coardele.nb

f[x_] := 2 * x ^ 3 - 3 * x ^ 2 - 12 * x + 12;
f[- 2.2746402426994083]
0.235795