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
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: ********************************
n= 0 a= -1.000000e+000, f(a)= 1.000000e+000
**************** Result Has Converged: *********************
the requested number of movie frames 10 is too large and
|
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.
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: ********************************
n= 0 a= -1.000000e+000, f(a)= 1.000000e+000
**************** Result Has Converged: *********************
the requested number of movie frames 10 is too large and
|
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.
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: ********************************
n= 0 a= -1.000000e+000, f(a)= 1.000000e+000
**************** Result Has Converged: *********************
the requested number of movie frames 10 is too large and
|
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.
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: ********************************
n= 0 a= -3.000000e-001, f(a)= 4.708182e-001
**************** Result Has Converged: *********************
the requested number of movie frames 10 is too large and
|
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: ********************************
n= 0 a= 1.000000e+000, f(a)= 6.321206e-001
**************** Result Has Converged: *********************
|
![]() |
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: ********************************
n= 0 a= 1.000000e+000, f(a)= 9.932621e-001
**************** Result Has Converged: *********************
>> |
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.
Files used and produced:
f_10.m
run_me10.m
output10.txt
| Function Name: f4_10
************************** Initial Input Values: ********************************
n= 0 a= 1.000000e+000, f(a)= 9.999546e-001
**************** Result Has Converged: *********************
|
![]() |
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.