MATH 4650-001: Numerical Analysis I
Project - The Secant Method

Dmitriy Tserekhman
 
 

Testing Procedures:

Part 1 - Testing code for the example provided on page 125.                                                                                  Main Page
Part 2 and Part 3 - Testing code for different functions and comparing them with the Secant Method LIVE


Part 1

One of the test cases used to verify the validity of the program's output was to use an example provided in the text book on page 125.

First, the given function f(x) = x^5 + x^3 + 3 was tested with the secant tolerance of 10^(-5). The output of such execution is shown below:

Files used to produce such output were:     f.m    run_me1_1.m    output1_1.txt
 
 

>> run_me1_1
*************** Specifications on Given Computing Machine ***********************
Floating point relative accuracy (eps) is: 2.220446e-016 
Smallest positive floating point number is: 2.225074e-308 
Largest positive floating point number is: 1.797693e+308 
*********************************************************************************

 Function Name: f

************************** Initial Input Values: ********************************
x_0= 1.000000e+000, x_1=-1.000000e+000, f(x_0)= 5.000000e+000, f(x_1)= 1.000000e+000 
*********************************************************************************

n= 0 a= -1.000000e+000, f(a)= 1.000000e+000 
n= 1 a= 1.000000e+000, f(a)= 5.000000e+000 
n= 2, a= -1.500000e+000, f(a)= -7.968750e+000 
n= 3, a= -1.055749e+000, f(a)= 5.116487e-001 
n= 4, a= -1.114158e+000, f(a)= -9.991207e-002 
n= 5, a= -1.104615e+000, f(a)= 7.593217e-003 
n= 6, a= -1.105289e+000, f(a)= 1.011787e-004 

**************** Result Has Converged: *********************
Converged within the tolerance 1.000000e-005 
The found zero is: -1.105289e+000 
************************************************************

the requested number of movie frames 10 is too large and 
 will be reduced to 5 to match the data 
>> 

From the above output, it can be seen that the received values are very close to the ones presented in the book for the given example. In fact, it can be noted that the values received above are actually more accurate then the ones provided in Marc-32 output. The reason behind it is that even though the error tolerance was simulated to be not very low, the resulted values were more accurate due to the nature of the used computer architecture itself. From the first couple lines of the output, it can be seen that the machine epsilon of that computer is 2.220446e-016 and the smallest positive floating point number is 2.225074e-308. However, due to the nature of implemented secant algorithm, it can be seen that the error tolerance plays role in the number of iteration being produced. Specifically, the used error tolerance produces only 7 iterations; whereas, the book's example shows 9.



In order to produce the same number of iterations as the book specifies, the secant error tolerance was changed to 2^(-23), closer to the tolerance of Marc-32. The received output is shown below:

The used files were:                                                  f.m        run_me1_2       output1_2
Produced Movie file:        movie_f.avi
 

>> run_me1_2
*************** Specifications on Given Computing Machine ***********************
Floating point relative accuracy (eps) is: 2.220446e-016 
Smallest positive floating point number is: 2.225074e-308 
Largest positive floating point number is: 1.797693e+308 
*********************************************************************************

 Function Name: f

************************** Initial Input Values: ********************************
x_0= 1.000000e+000, x_1=-1.000000e+000, f(x_0)= 5.000000e+000, f(x_1)= 1.000000e+000 
*********************************************************************************

n= 0 a= -1.000000e+000, f(a)= 1.000000e+000 
n= 1 a= 1.000000e+000, f(a)= 5.000000e+000 
n= 2, a= -1.500000e+000, f(a)= -7.968750e+000 
n= 3, a= -1.055749e+000, f(a)= 5.116487e-001 
n= 4, a= -1.114158e+000, f(a)= -9.991207e-002 
n= 5, a= -1.104615e+000, f(a)= 7.593217e-003 
n= 6, a= -1.105289e+000, f(a)= 1.011787e-004 
n= 7, a= -1.105299e+000, f(a)= -1.045169e-007 

**************** Result Has Converged: *********************
Converged within the tolerance 1.192093e-007 
The found zero is: -1.105299e+000 
************************************************************

the requested number of movie frames 10 is too large and 
 will be reduced to 6 to match the data 
>> 

This time, the number of obtained iterations only increased by 1. The above attached movie file shows how solution converges to the received zero of the function by indicating the converging point with the red dot.



Finally, it was decided to see the maximum number of iterations that could be produced when the error tolerance is equal to the given machine epsilon.

Such test case is presented below:
Used files:                                                          f.m          run_me1_3.m         output1_3.txt
 
 

>> run_me1_3
*************** Specifications on Given Computing Machine ***********************
Floating point relative accuracy (eps) is: 2.220446e-016 
Smallest positive floating point number is: 2.225074e-308 
Largest positive floating point number is: 1.797693e+308 
*********************************************************************************

 Function Name: f

************************** Initial Input Values: ********************************
x_0= 1.000000e+000, x_1=-1.000000e+000, f(x_0)= 5.000000e+000, f(x_1)= 1.000000e+000 
*********************************************************************************

n= 0 a= -1.000000e+000, f(a)= 1.000000e+000 
n= 1 a= 1.000000e+000, f(a)= 5.000000e+000 
n= 2, a= -1.500000e+000, f(a)= -7.968750e+000 
n= 3, a= -1.055749e+000, f(a)= 5.116487e-001 
n= 4, a= -1.114158e+000, f(a)= -9.991207e-002 
n= 5, a= -1.104615e+000, f(a)= 7.593217e-003 
n= 6, a= -1.105289e+000, f(a)= 1.011787e-004 
n= 7, a= -1.105299e+000, f(a)= -1.045169e-007 
n= 8, a= -1.105299e+000, f(a)= 1.436185e-012 
n= 9, a= -1.105299e+000, f(a)= 0.000000e+000 

**************** Result Has Converged: *********************
Converged within the tolerance 2.220446e-016 
The found zero is: -1.105299e+000 
************************************************************

the requested number of movie frames 10 is too large and 
 will be reduced to 8 to match the data 
>> 

This time, the secant method produced 10 iterations, and the 10th iteration has produced a finite result. The function value has actually reached a true zero at specified point. Nevertheless, it is recognized that function values for iteration numbers 7 and 8 differ from iterations 7 and 8 presented in the book's output. The values computed by the used computer are much smaller than the ones computed by Marc-32, which points out one more time that the used computer is more accurate, and is able to represent much smaller numbers than Marc-32 architecture.
 



 

Part 2 and Part 3

Problem 1 on page 131.

The  problem asks to find the zero near -0.5 of f(x) = e^x - 3x^2. This problem implies that if the correct initial points are found, the result should be close to -0.5. The output below shows the expected result found with initial points of -0.3 and -0.1.

Files used and produced in this case:     f2.m    run_me2.m      output2.txt        movie_f2.avi
 
 

>> run_me2
*************** Specifications on Given Computing Machine ***********************
Floating point relative accuracy (eps) is: 2.220446e-016 
Smallest positive floating point number is: 2.225074e-308 
Largest positive floating point number is: 1.797693e+308 
*********************************************************************************

 Function Name: f2

************************** Initial Input Values: ********************************
x_0= -3.000000e-001, x_1=-1.000000e-001, f(x_0)= 4.708182e-001, f(x_1)= 8.748374e-001 
*********************************************************************************

n= 0 a= -3.000000e-001, f(a)= 4.708182e-001 
n= 1 a= -1.000000e-001, f(a)= 8.748374e-001 
n= 2, a= -5.330673e-001, f(a)= -2.656798e-001 
n= 3, a= -4.489920e-001, f(a)= 3.348974e-002 
n= 4, a= -4.584036e-001, f(a)= 1.890694e-003 
n= 5, a= -4.589667e-001, f(a)= -1.507017e-005 
n= 6, a= -4.589623e-001, f(a)= 6.677269e-009 

**************** Result Has Converged: *********************
Converged within the tolerance 1.000000e-006 
The found zero is: -4.589623e-001 
************************************************************

the requested number of movie frames 10 is too large and 
 will be reduced to 5 to match the data 
>> 

The movie file for this example specifies the function's region where its graph has linear appearance.


The following section runs couple more examples from various book problems and compares the results obtained by the Secant Method LIVE.

The next three outputs demonstrate results of evaluating function f(x) = 2e^(-k)x + 1 - 3e^(-kx) from problem 8 on page 132 with k values being equal to 1, 5, and 10.

k = 1     =>  files used and produced: f4_1.m       run_me4_1.m         output4_1.txt
 
 

 Function Name: f4_1

************************** Initial Input Values: ********************************
x_0= 0.000000e+000, x_1=1.000000e+000, f(x_0)= -2.000000e+000, f(x_1)= 6.321206e-001 
*********************************************************************************

n= 0 a= 1.000000e+000, f(a)= 6.321206e-001 
n= 1 a= 0.000000e+000, f(a)= -2.000000e+000 
n= 2, a= 7.598436e-001, f(a)= 1.558430e-001 
n= 3, a= 6.812619e-001, f(a)= -1.668969e-002 
n= 4, a= 6.888634e-001, f(a)= 3.979695e-004 
n= 5, a= 6.886864e-001, f(a)= 9.926078e-007 

**************** Result Has Converged: *********************
Converged within the tolerance 1.000000e-006 
The found zero is: 6.886864e-001 
************************************************************



The next picture shows output when k = 5

Files used and produced:     f4_5.m          run_me4_5.m             output4_5.txt                movie_f4_5.avi
 
 

 Function Name: f4_5

************************** Initial Input Values: ********************************
x_0= 0.000000e+000, x_1=1.000000e+000, f(x_0)= -2.000000e+000, f(x_1)= 9.932621e-001 
*********************************************************************************

n= 0 a= 1.000000e+000, f(a)= 9.932621e-001 
n= 1 a= 0.000000e+000, f(a)= -2.000000e+000 
n= 2, a= 6.681674e-001, f(a)= 9.027822e-001 
n= 3, a= -2.642764e+000, f(a)= -1.643655e+006 
n= 4, a= 6.681655e-001, f(a)= 9.027812e-001 
n= 5, a= -9.895668e-001, f(a)= -4.216218e+002 
n= 6, a= 6.646236e-001, f(a)= 9.008355e-001 
n= 7, a= -9.752827e-001, f(a)= -3.924915e+002 
n= 8, a= 6.608683e-001, f(a)= 8.987356e-001 
n= 9, a= -9.463490e-001, f(a)= -3.394930e+002 
n= 10, a= 6.566248e-001, f(a)= 8.963159e-001 
n= 11, a= -9.152745e-001, f(a)= -2.904962e+002 
n= 12, a= 6.517897e-001, f(a)= 8.934971e-001 
n= 13, a= -8.808065e-001, f(a)= -2.443518e+002 
n= 14, a= 6.462060e-001, f(a)= 8.901579e-001 
n= 15, a= -8.422784e-001, f(a)= -2.013625e+002 
n= 16, a= 6.396548e-001, f(a)= 8.861221e-001 
n= 17, a= -7.987560e-001, f(a)= -1.617895e+002 
n= 18, a= 6.318196e-001, f(a)= 8.811222e-001 
n= 19, a= -7.489883e-001, f(a)= -1.259297e+002 
n= 20, a= 6.222253e-001, f(a)= 8.747328e-001 
n= 21, a= -6.912631e-001, f(a)= -9.410920e+001 
n= 22, a= 6.101290e-001, f(a)= 8.662369e-001 
n= 23, a= -6.231953e-001, f(a)= -6.667472e+001 
n= 24, a= 5.943112e-001, f(a)= 8.543382e-001 
n= 25, a= -5.414290e-001, f(a)= -4.396658e+001 
n= 26, a= 5.726627e-001, f(a)= 8.364792e-001 
n= 27, a= -4.413064e-001, f(a)= -2.625843e+001 
n= 28, a= 5.413592e-001, f(a)= 8.070443e-001 
n= 29, a= -3.169183e-001, f(a)= -1.363617e+001 
n= 30, a= 4.934012e-001, f(a)= 7.521336e-001 
n= 31, a= -1.634981e-001, f(a)= -5.796630e+000 
n= 32, a= 4.179555e-001, f(a)= 6.344883e-001 
n= 33, a= 1.105911e-002, f(a)= -1.838467e+000 
n= 34, a= 3.135577e-001, f(a)= 3.787083e-001 
n= 35, a= 1.589863e-001, f(a)= -3.526939e-001 
n= 36, a= 2.335231e-001, f(a)= 6.982348e-002 
n= 37, a= 2.212055e-001, f(a)= 1.036873e-002 
n= 38, a= 2.190573e-001, f(a)= -3.791344e-004 
n= 39, a= 2.191331e-001, f(a)= 1.962248e-006 

**************** Result Has Converged: *********************
Converged within the tolerance 1.000000e-006 
The found zero is: 2.191331e-001 
************************************************************

>> 

         some more iterations here

The movie file for this example depicts the exponential nature of the given function, and it is clearly seen where solution resides.



The next output screen shown below illustrates results from the above function when k = 10:

Files used and produced:      f_10.m           run_me10.m             output10.txt
 
 

 Function Name: f4_10

************************** Initial Input Values: ********************************
x_0= 0.000000e+000, x_1=1.000000e+000, f(x_0)= -2.000000e+000, f(x_1)= 9.999546e-001 
*********************************************************************************

n= 0 a= 1.000000e+000, f(a)= 9.999546e-001 
n= 1 a= 0.000000e+000, f(a)= -2.000000e+000 
n= 2, a= 6.666768e-001, f(a)= 9.962430e-001 
n= 3, a= -8.880216e+001, f(a)= -Inf 

**************** Result Has Converged: *********************
Converged within the tolerance 1.000000e-006 
The found zero is: 6.666768e-001 
************************************************************

From the above three comparisons it can be seen that the results being produced are very close to the Secant Method LIVE, which proves that the implemented Secant Method satisfies the functional requirements. The only difference is in the first two iterations where the resulted values are being swapped due to the nature of the implemented secant algorithm.


                                       Main Page                                       Top                                   Next to ===> Analysis Section