Practical 3
Practical 3
Practical 3
SECANT METHOD
40
20
Out[1]=
-4 -2 2 4
-20
-40
-60
In[3]:= x[0] = 0;
x[1] = 1;
f[x_] := x3 - 5 * x + 1;
Fori = 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
10
Out[8]=
4
-2 -1 1 2
In[10]:= x[0] = 0;
x[1] = 1;
f[x_] := x * Exp[x] - Cos[x];
Fori = 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
40
30
20
Out[15]=
10
-2 -1 1 2 3 4
-10
-20
In[17]:= x[0] = 2;
x[1] = 3;
f[x_] := x3 - 17;
Fori = 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
Out[22]= 1
-1
In[24]:= x[0] = 0;
x[1] = 1;
f[x_] := x3 - 3 * x + 1;
Fori = 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
Out[29]=
In[31]:= x[0] = 0;
x[1] = 1;
f[x_] := -x - x;
Fori = 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