Secant Method 28-1-23 Final-1

You might also like

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

SECANT METHOD :

Question 1 →
In[157]:=

f[x_] = x ^ 3 + 2 * x ^ 2 - 3 * x - 1;
Subscriptp, 0 = 2;

Subscriptp, 1 = 1;

er = 0.000005;
Forn = 2, n < 11, n ++,

Subscriptp, n =

NSubscriptp, n - 1 -

fSubscript

p, n - 1 Subscriptp, n - 1 - Subscript

p, n - 2  fSubscriptp, n - 1 -

fSubscriptp, n - 2;

IfAbsSubscriptp, n - Subscriptp, n - 1 < er, Break[];

Printn - 1, "th Iteration value", Subscriptp, n;

Print"Estimated error is",

AbsSubscriptp, n - Subscriptp, n - 1

;

Plot x ^ 3 + 2 x ^ 2 - 3 x - 1, x, - 4, 4, PlotStyle → Orange, Frame → True,

GridLines → Automatic

1th Iteration value1.1

Estimated error is0.1

2th Iteration value1.22173

Estimated error is0.121729

3th Iteration value1.19649

Estimated error is0.0252442

4th Iteration value1.19865

Estimated error is0.00216004

5th Iteration value1.19869

Estimated error is0.000045968


2

Out[162]=

40

30

20

10

-10

-20

-4 -2 0 2 4

Question 2 →
In[175]:=

f[x_] = Exp[- x] - x;
Subscriptp, 0 = 2;

Subscriptp, 1 = 1;

er = 10 ^ - 5;
Forn = 2, n < 11, n ++,

Subscriptp, n =

NSubscriptp, n - 1 -

fSubscript

p, n - 1 Subscriptp, n - 1 - Subscript

p, n - 2  fSubscriptp, n - 1 -

fSubscriptp, n - 2;

IfAbsSubscriptp, n - Subscriptp, n - 1 < er, Break[];

Printn - 1, "th Iteration value", Subscriptp, n;

Print"Estimated error is",

AbsSubscriptp, n - Subscriptp, n - 1

PlotExp[- x] - x, x, - 3, 4, PlotStyle → Blue, Frame → True,

GridLines → Automatic
3

1th Iteration value0.487142

Estimated error is0.512858

2th Iteration value0.573076

Estimated error is0.0859347

3th Iteration value0.56723

Estimated error is0.00584616

4th Iteration value0.567143

Estimated error is0.0000869484


Out[180]=

20

15

10

-5
-3 -2 -1 0 1 2 3 4

Question 3 →
4

In[181]:=

f[x_] = Exp[x] ^ 2 + x;
Subscriptp, 0 = 2;

Subscriptp, 1 = 1;

er = 0.000005;
Forn = 2, n < 11, n ++,

Subscriptp, n =

NSubscriptp, n - 1 -

fSubscript

p, n - 1 Subscriptp, n - 1 - Subscript

p, n - 2  fSubscriptp, n - 1 -

fSubscriptp, n - 2;

IfAbsSubscriptp, n - Subscriptp, n - 1 < er, Break[];

Printn - 1, "th Iteration value", Subscriptp, n;

Print"Estimated error is",

AbsSubscriptp, n - Subscriptp, n - 1

;

Plot Exp[x] ^ 2 + x, x, - 4, 4, PlotStyle → Orange, Frame → True,

GridLines → Automatic
5

1th Iteration value0.825986

Estimated error is0.174014

2th Iteration value0.377694

Estimated error is0.448292

3th Iteration value0.0600681

Estimated error is0.317626

4th Iteration value- 0.226072

Estimated error is0.28614

5th Iteration value- 0.377027

Estimated error is0.150956

6th Iteration value- 0.421551

Estimated error is0.0445237

7th Iteration value- 0.426194

Estimated error is0.00464287

8th Iteration value- 0.426303

Estimated error is0.0001087


Out[186]=

400

300

200

100

-4 -2 0 2 4

Question 4 →
6

In[187]:=

f[x_] = x ^ 3 - 5 x + 1;
Subscriptp, 0 = 1;

Subscriptp, 1 = 2;

er = 0;
Forn = 2, n < 7, n ++,

Subscriptp, n =

NSubscriptp, n - 1 -

fSubscript

p, n - 1 Subscriptp, n - 1 - Subscript

p, n - 2  fSubscriptp, n - 1 -

fSubscriptp, n - 2;

IfAbsSubscriptp, n - Subscriptp, n - 1 < er, Break[];

Printn - 1, "th Iteration value", Subscriptp, n;

Print"Estimated error is",

AbsSubscriptp, n - Subscriptp, n - 1

;

Plot x ^ 3 - 5 x + 1, x, - 4, 4, PlotStyle → Orange, Frame → True,

GridLines → Automatic

1th Iteration value2.5

Estimated error is0.5

2th Iteration value2.09756

Estimated error is0.402439

3th Iteration value2.12134

Estimated error is0.0237786

4th Iteration value2.12859

Estimated error is0.0072456

5th Iteration value2.12842

Estimated error is0.000166952


7

Out[192]=
20

15

10

-5

-10

-15

-4 -2 0 2 4

Question 5 →
In[199]:=

f[x_] = Sin[x] - x;
Subscriptp, 0 = 2;

Subscriptp, 1 = 1;

er = 0.000001;
Forn = 2, n < 11, n ++,

Subscriptp, n =

NSubscriptp, n - 1 -

fSubscript

p, n - 1 Subscriptp, n - 1 - Subscript

p, n - 2  fSubscriptp, n - 1 -

fSubscriptp, n - 2;

IfAbsSubscriptp, n - Subscriptp, n - 1 < er, Break[];

Printn - 1, "th Iteration value", Subscriptp, n;

Print"Estimated error is",

AbsSubscriptp, n - Subscriptp, n - 1

;

Plot Sin[x] - x, x, - 14, 14, PlotStyle → Red, Frame → True,

GridLines → Automatic
8

1th Iteration value0.829936

Estimated error is0.170064

2th Iteration value0.594471

Estimated error is0.235465

3th Iteration value0.45396

Estimated error is0.140511

4th Iteration value0.339644

Estimated error is0.114316

5th Iteration value0.256619

Estimated error is0.0830243

6th Iteration value0.193374

Estimated error is0.063245

7th Iteration value0.145955

Estimated error is0.0474191

8th Iteration value0.110133

Estimated error is0.035822

9th Iteration value0.0831286

Estimated error is0.0270047


Out[204]=

10

-5

-10

-10 -5 0 5 10

You might also like