Practical 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

PRACTICAL 3

SECANT METHOD

Ques 1. Find the smallest positive root of the equation


x3 - 5 x + 1 = 0
In[1]:= Plotx3 - 5 * x + 1, {x, - 5, 5}

40

20

Out[1]=
-4 -2 2 4

-20

-40

-60

In[2]:= Solvex3 - 5 * x + 1  0, x, Reals // N


Out[2]= {{x  - 2.33006}, {x  0.20164}, {x  2.12842}}
2 Practical_3.nb

In[3]:= x[0] = 0;
x[1] = 1;
f[x_] := x3 - 5 * x + 1;
Fori = 1, i ≤ 10, i ++,
x[i - 1] * f[x[i]] - f[x[i - 1]] * x[i]
x[i + 1] = ;
f[x[i]] - f[x[i - 1]]
;
TableForm[Table[{i, x[i], f[x[i]]}, {i, 0, 10}],
TableHeadings  {{}, {"i", "x[i]", "f[x[i]]"}}] // N
Out[7]//TableForm=
i x[i] f[x[i]]
0. 0. 1.
1. 1. - 3.
2. 0.25 - 0.234375
3. 0.186441 0.0742773
4. 0.201736 - 0.000471116
5. 0.20164 - 8.64229 × 10-7
6. 0.20164 1.03525 × 10-11
7. 0.20164 - 2.27449 × 10-19
8. 0.20164 - 5.98605 × 10-32
9. 0.20164 3.46126 × 10-52
10. 0.20164 - 5.26725 × 10-85

Output : The smallest positive root of the equation is 0.20164.

Ques 2: Find the smallest positive root of the equation


x * e x -Cos x= 0
In[8]:= Plot[x * Exp[x] - Cos[x], {x, - 2, 2}]

10

Out[8]=
4

-2 -1 1 2

In[9]:= NSolve[x * Exp[x] - Cos[x]  0 && - 2 ≤ x ≤ 2, x, Reals]


Out[9]= {{x  - 1.864}, {x  0.517757}}
Practical_3.nb 3

In[10]:= x[0] = 0;
x[1] = 1;
f[x_] := x * Exp[x] - Cos[x];
Fori = 1, i ≤ 7, i ++,
x[i - 1] * f[x[i]] - f[x[i - 1]] * x[i]
x[i + 1] = ;
f[x[i]] - f[x[i - 1]]
;
TableForm[Table[{i, x[i], f[x[i]]}, {i, 0, 7}],
TableHeadings  {{}, {"i", "x[i]", "f[x[i]]"}}] // N
Out[14]//TableForm=
i x[i] f[x[i]]
0. 0. - 1.
1. 1. 2.17798
2. 0.314665 - 0.519871
3. 0.446728 - 0.203545
4. 0.531706 0.0429311
5. 0.516904 - 0.00259276
6. 0.517747 - 0.0000301119
7. 0.517757 2.15132 × 10-8

Output : The smallest positive root of the equation is 0.517757.

Ques 3. Find the smallest positive root of the equation


x 3 - 17 = 0
In[15]:= Plotx3 - 17, {x, - 2, 4}
50

40

30

20

Out[15]=
10

-2 -1 1 2 3 4

-10

-20

In[16]:= Solvex3 - 17  0, x, Reals // N


Out[16]= {{x  2.57128}}
4 Practical_3.nb

In[17]:= x[0] = 2;
x[1] = 3;
f[x_] := x3 - 17;
Fori = 1, i ≤ 7, i ++,
x[i - 1] * f[x[i]] - f[x[i - 1]] * x[i]
x[i + 1] = ;
f[x[i]] - f[x[i - 1]]
;
TableForm[Table[{i, x[i], f[x[i]]}, {i, 0, 7}],
TableHeadings  {{}, {"i", "x[i]", "f[x[i]]"}}] // N
Out[21]//TableForm=
i x[i] f[x[i]]
0. 2. - 9.
1. 3. 10.
2. 2.47368 - 1.86325
3. 2.55635 - 0.294492
4. 2.57187 0.0115819
5. 2.57128 - 0.0000675036
6. 2.57128 - 1.53241 × 10-8
7. 2.57128 2.0283 × 10-14

Output : The smallest positive root of the equation is 2.57128.

Ques 4. Find the smallest positive root of the equation


x3 - 3 x + 1 = 0
In[22]:= Plotx3 - 3 * x + 1, {x, - 1, 1}

Out[22]= 1

-1.0 -0.5 0.5 1.0

-1

In[23]:= Solvex3 - 3 * x + 1  0, x, Reals // N


Out[23]= {{x  - 1.87939}, {x  0.347296}, {x  1.53209}}
Practical_3.nb 5

In[24]:= x[0] = 0;
x[1] = 1;
f[x_] := x3 - 3 * x + 1;
Fori = 1, i ≤ 10, i ++,
x[i - 1] * f[x[i]] - f[x[i - 1]] * x[i]
x[i + 1] = ;
f[x[i]] - f[x[i - 1]]
;
TableForm[Table[{i, x[i], f[x[i]]}, {i, 0, 10}],
TableHeadings  {{}, {"i", "x[i]", "f[x[i]]"}}] // N
Out[28]//TableForm=
i x[i] f[x[i]]
0. 0. 1.
1. 1. - 1.
2. 0.5 - 0.375
3. 0.2 0.408
4. 0.356322 - 0.023725
5. 0.347731 - 0.00114732
6. 0.347295 4.14303 × 10-6
7. 0.347296 - 7.1212 × 10-10
8. 0.347296 - 4.41662 × 10-16
9. 0.347296 4.7083 × 10-26
10. 0.347296 - 3.11297 × 10-42

Output : The smallest positive root of the equation is 0.347296.

Ques 5: Find the smallest positive root of the equation


e- x - x = 0
In[29]:= Plot[Exp[- x] - x, {x, - 1, 1}]

Out[29]=

-1.0 -0.5 0.5 1.0

In[30]:= Solve[Exp[- x] - x  0 && - 1 ≤ x ≤ 1, x, Reals] // N


Out[30]= {{x  0.567143}}
6 Practical_3.nb

In[31]:= x[0] = 0;
x[1] = 1;
f[x_] := -x - x;
Fori = 1, i ≤ 5, i ++,
x[i - 1] * f[x[i]] - f[x[i - 1]] * x[i]
x[i + 1] = ;
f[x[i]] - f[x[i - 1]]
;
TableForm[Table[{i, x[i], f[x[i]]}, {i, 0, 5}],
TableHeadings  {{}, {"i", "x[i]", "f[x[i]]"}}] // N
Out[35]//TableForm=
i x[i] f[x[i]]
0. 0. 1.
1. 1. - 0.632121
2. 0.6127 - 0.0708139
3. 0.563838 0.00518235
4. 0.56717 - 0.0000424192
5. 0.567143 - 2.53802 × 10-8

Output : The smallest positive root of the equation is 0.567143.

You might also like