@@ -24,7 +24,7 @@ Bisection Method is a root finding method that solves the form: f(x) = 0.
24
24
25
25
The current low guess, high guess, tol, and N for demonstration is (1, 2, 10^-5, 100) respectively
26
26
* Note these can be changed under:
27
- ```
27
+ ``` python
28
28
# globals
29
29
TOL = 10 **- 5
30
30
A = 1
@@ -34,13 +34,13 @@ N = 100
34
34
35
35
The current fucntion for demonstration is: f(x) = x^3 - x - 2
36
36
* Note this can be changed under:
37
- ```
37
+ ``` python
38
38
def f (x ):
39
39
return (math.pow(x,3 ) - x - 2 )
40
40
```
41
41
42
42
Run from command line:
43
- ```
43
+ ``` python
44
44
$ ./ bisection.py
45
45
Bisection method soln: x = 1.52138519287
46
46
```
@@ -52,7 +52,7 @@ The Fixed-Point Iteration Method finds the root of an equation in the form: x =
52
52
53
53
The current approx, tol, and N for demonstration is (4.6, 10^-4, 100) respectively
54
54
* Note these can be changed under:
55
- ```
55
+ ``` python
56
56
# globals
57
57
APPROX = 4.6
58
58
TOL = 10 **- 4
@@ -61,13 +61,13 @@ N = 100
61
61
62
62
The current fucntion for demonstration is: f(x) = (1/tan(x))- (1/x) + x
63
63
* Note this can be changed under:
64
- ```
64
+ ``` python
65
65
def f (x ):
66
66
return (1 / math.tan(x)) - (1 / x) + x
67
67
```
68
68
69
69
Run from command line:
70
- ```
70
+ ``` python
71
71
$ ./ fixedPoint.py
72
72
Fixed point solution: x = 4.49340945791
73
73
```
@@ -78,7 +78,7 @@ The Newton's Method finds the root of an equation: x : f(x) = 0
78
78
79
79
The current approx, tol, and N for demonstration is (4.6, 10^-4, 100) respectively
80
80
* Note these can be changed under:
81
- ```
81
+ ``` python
82
82
# globals
83
83
APPROX = 0.1
84
84
TOL = 10 **- 5
@@ -87,20 +87,20 @@ N = 100
87
87
88
88
The current fucntion for demonstration is: f(x) = (1 + x)^204 - 440x - 1
89
89
* Note this can be changed under:
90
- ```
90
+ ``` python
91
91
def f (x ):
92
92
return math.pow((1 + x),204 )- 440 * x- 1
93
93
```
94
94
95
95
For Newton's Method we also need to know f'(x). Currently, f'(x) = 204* (1 + x)^203 - 440
96
96
* Note that this MUST be changed when f(x) is changed. Do this under:
97
- ```
97
+ ``` python
98
98
def fprime (x ):
99
99
return 204 * math.pow((x+ 1 ),203 ) - 440
100
100
```
101
101
102
102
Run from command line:
103
- ```
103
+ ``` python
104
104
$ ./ newtons.py
105
105
Newton' s Method soln: x = 0.00681932148758
106
106
```
@@ -112,7 +112,7 @@ The Newton's Method finds the root of an equation: x : f(x) = 0. Considered an
112
112
113
113
The current approx, tol, and N for demonstration is (4.6, 10^-4, 100) respectively
114
114
* Note these can be changed under:
115
- ```
115
+ ``` python
116
116
# globals
117
117
APPROX = 0.1
118
118
TOL = 10 **- 5
@@ -121,13 +121,13 @@ N = 100
121
121
122
122
The current fucntion for demonstration is: f(x) = (1 + x)^204 - 440x - 1
123
123
* Note this can be changed under:
124
- ```
124
+ ``` python
125
125
def f (x ):
126
126
return math.pow((1 + x),204 )- 440 * x- 1
127
127
```
128
128
129
129
Run from command line:
130
- ```
130
+ ``` python
131
131
$ ./ secant.py
132
132
Secant method soln: x = 0.00681932406799
133
133
```
0 commit comments