From the picture above we can know that the root of \(f(x)\) is close with \(2\), or we can say also root of \(f(x)\) is on range \([1.5, 2.5]\), so we can use \(2\) or \([1.5,2.5]\) to become initial value/range in estimating root of \(f(x)\).
# root_fixedpoint_1_tableroot_fixedpoint_1_table <-data.frame(iteration =0:root_fixedpoint_1$much_iter,root = root_fixedpoint_1$root_complete,residual = root_fixedpoint_1$residu,abs_f_root = root_fixedpoint_1$abs_f_root )root_fixedpoint_1_table[rownames(root_fixedpoint_1_table) =="1","residual"] <-NA# insert root_fixedpoint_1_table# into a kable formatkable( root_fixedpoint_1_table,digits =10,caption ="Trace of Root of f(x) With Fixed Point Method")
Trace of Root of f(x) With Fixed Point Method
iteration
root
residual
abs_f_root
0
2.000000
NA
1.0000000000
1
2.080084
0.0800838231
0.1601676461
2
2.092351
0.0122668547
0.0245337095
3
2.094217
0.0018663182
0.0037326364
4
2.094501
0.0002836562
0.0005673124
5
2.094544
0.0000431053
0.0000862107
6
2.094550
0.0000065503
0.0000131006
7
2.094551
0.0000009954
0.0000019907
8
2.094551
0.0000001513
0.0000003025
Convergence Status of Estimated Root of\(f(x)\).
Be noticed, since from iteration\(4\) the root value had been sticking in \(2.0945\) and on the same time abs_f_root value had been starting to approximate \(0\), then we can reveal that the estimated roots from each iteration are convergent to a specific value (that is \(2.094551\)). Based on that findings, we can define the convergence status of root which obtained by using Fixed Point method as like this.
# root_newtonraphson_1_tableroot_newtonraphson_1_table <-data.frame(iteration =0:root_newtonraphson_1$much_iter,root = root_newtonraphson_1$root_complete,residual = root_newtonraphson_1$residu,abs_f_root = root_newtonraphson_1$abs_f_root )root_newtonraphson_1_table[rownames(root_newtonraphson_1_table) =="1","residual"] <-NA# insert root_newtonraphson_1_table# into a kable formatkable( root_newtonraphson_1_table,digits =10,caption ="Trace of Root of f(x) With Newton Raphson Method")
Trace of Root of f(x) With Newton Raphson Method
iteration
root
residual
abs_f_root
0
2.000000
NA
1.0000000000
1
2.100000
0.1000000000
0.0610000000
2
2.094568
-0.0054318789
0.0001857232
3
2.094551
-0.0000166394
0.0000000017
Convergence Status of Estimated Root of\(f(x)\).
Be noticed, since from iteration\(2\) the root value had been sticking in \(2.0945\) and on the same time abs_f_root value had been starting to approximate \(0\), then we can reveal that the estimated roots from each iteration are convergent to a specific value (that is \(2.094551\)). Based on that findings, we can define the convergence status of root which obtained by using Newton Raphson method as like this.
# root_secant_1_tableroot_secant_1_table <-data.frame(iteration =0:(root_secant_1$much_iter +1),root = root_secant_1$root_complete,residual = root_secant_1$residu,abs_f_root = root_secant_1$abs_f_root )root_secant_1_table[rownames(root_secant_1_table) =="1","residual"] <-NA# insert root_secant_1_table# into a kable formatkable( root_secant_1_table,digits =10,caption ="Trace of Root of f(x) With Secant Method")
Trace of Root of f(x) With Secant Method
iteration
root
residual
abs_f_root
0
1.500000
NA
4.6250000000
1
2.500000
1.0000000000
5.6250000000
2
1.951220
-0.5487804878
1.4736437370
3
2.065144
0.1139241465
0.3228247858
4
2.097101
0.0319577099
0.0285012776
5
2.094509
-0.0025925647
0.0004763332
6
2.094551
0.0000426165
0.0000006831
Convergence Status of Estimated Root of\(f(x)\).
Be noticed, since from iteration\(5\) the root value had been sticking in \(2.0945\) and on the same time abs_f_root value had been starting to approximate \(0\), then we can reveal that the estimated roots from each iteration are convergent to a specific value (that is \(2.094551\)). Based on that findings, we can define the convergence status of root which obtained by using Secant method as like this.
# root_bisection_1_tableroot_bisection_1_table <-data.frame(iteration =1:root_bisection_1$much_iter,root = root_bisection_1$root_complete,residual = root_bisection_1$residu,abs_f_root = root_bisection_1$abs_f_root )root_bisection_1_table[rownames(root_bisection_1_table) =="1","residual"] <-NA# insert root_bisection_1_table# into a kable formatkable( root_bisection_1_table,digits =10,caption ="Trace of Root of f(x) With Bisection Method")
Trace of Root of f(x) With Bisection Method
iteration
root
residual
abs_f_root
1
2.000000
NA
1.0000000000
2
2.250000
0.2500000000
1.8906250000
3
2.125000
-0.1250000000
0.3457031250
4
2.062500
-0.0625000000
0.3513183594
5
2.093750
0.0312500000
0.0089416504
6
2.109375
0.0156250000
0.1668357849
7
2.101562
-0.0078125000
0.0785622597
8
2.097656
-0.0039062500
0.0347142816
9
2.095703
-0.0019531250
0.0128623322
10
2.094727
-0.0009765625
0.0019543478
11
2.094238
-0.0004882812
0.0034951492
12
2.094482
0.0002441406
0.0007707752
13
2.094604
0.0001220703
0.0005916927
14
2.094543
-0.0000610352
0.0000895647
15
2.094574
0.0000305176
0.0002510581
16
2.094559
-0.0000152588
0.0000807453
17
2.094551
-0.0000076294
0.0000044101
18
2.094555
0.0000038147
0.0000381675
19
2.094553
-0.0000019073
0.0000168787
20
2.094552
-0.0000009537
0.0000062343
21
2.094552
-0.0000004768
0.0000009121
Convergence Status of Estimated Root of\(f(x)\).
Be noticed, since from iteration\(14\) the root value had been sticking in \(2.0945\) and on the same time abs_f_root value had been starting to approximate \(0\), then we can reveal that the estimated roots from each iteration are convergent to a specific value (that is \(2.094552\)). Based on that findings, we can define the convergence status of root which obtained by using Bisection method as like this.
root_bisection_1_conv_status <-TRUE
Report of Estimation, Convergence Status, and\(|f(\hat{x})|\).
Which Method Writer Found Easiest To Implement and Why.
Disclaimer: this oppinion is subjective, maybe this opinion is not relate to other perople.
For me when I will find the root of \(f(x)\) manually (without using computer), I prefer to choose Bisection method, because this method does not require advanced formula to be utilized/implemented/memorized. But it is not as the same as when I will look the root of \(f(x)\) helped by computer. For me, the algorithm of Bisection method is more complex than other methods, where algorithm of other methods (especially Fixed Point and Newton Raphson) do not need to reverse variables, yet Bisection method requires it, make me have to find residual and abs_f_root outside of looping which is used for finding the root (where in other methods I can simultantly find the residual and abs_f_root in the same looping used for finding the root). So when using computer without helped of any helper-function (only using basic language programming) I prefer to use Fixed Point or Newton Raphson Method.
Simulation of Newton Raphson Method.
Disclaimer: this is not writer’s simulation - writer embedded this simulation from Geogebra site. True author of this simulation are: Κωνσταντίνος Ζυγούρης, TBennison, and Kathryn Peake.
Simulation of Bisection Method.
Disclaimer: this is not writer’s simulation - writer embedded this simulation from Geogebra site. True author of this simulation is: Zuzana Moravkova.
(B). Exercise 2
Consdier \(f(x) = x^3 - x - 1\).
Draw the graph and identify an interval likely to contain a root.
Implement and compare four methods.
Try at least two different initial guesses for Newton-Raphson.
Explain why an unsuitable Fixed-Point rearrangement may fail even if the equation is algebraically equivalent.
(B). Answer Exercise 2.
Defining Function\(f(x) = x^3 - x - 1\)and Graphing It Using Suitable Interval.
# f_2f_2 <-function(x) x^3- x -1# graph of f_2curve(f_2,xlim =c(-2,4),ylim =c(-7,7),lwd =2,col ="darkgreen",main ="Graph of f(x) = x^3 - x - 1",xlab ="x",ylab ="f(x)")abline(h =0,lty =2,lwd =1.5,col ="red")legend("topleft",legend ="f(x)",col ="darkgreen",lty =1,lwd =2)
From the picture above we can know that the root of \(f(x)\) is close with \(1\), or we can say also root of \(f(x)\) is on range \([1, 2]\), so we can use \(1\) or \([1,2]\) to become initial value/range in estimating root of \(f(x)\).
# root_fixedpoint_2_tableroot_fixedpoint_2_table <-data.frame(iteration =0:root_fixedpoint_2$much_iter,root = root_fixedpoint_2$root_complete,residual = root_fixedpoint_2$residu,abs_f_root = root_fixedpoint_2$abs_f_root )root_fixedpoint_2_table[rownames(root_fixedpoint_2_table) =="1","residual"] <-NA# insert root_fixedpoint_2_table# into a kable formatkable( root_fixedpoint_2_table,digits =10,caption ="Trace of Root of f(x) With Fixed Point Method")
Trace of Root of f(x) With Fixed Point Method
iteration
root
residual
abs_f_root
0
1.000000
NA
1.0000000000
1
1.259921
0.2599210499
0.2599210499
2
1.312294
0.0523727868
0.0523727868
3
1.322354
0.0100599825
0.0100599825
4
1.324269
0.0019149254
0.0019149254
5
1.324633
0.0003638807
0.0003638807
6
1.324702
0.0000691233
0.0000691233
7
1.324715
0.0000131299
0.0000131299
8
1.324717
0.0000024940
0.0000024940
9
1.324718
0.0000004737
0.0000004737
Convergence Status of Estimated Root of\(f(x)\).
Be noticed, since from iteration\(6\) the root value had been sticking in \(1.3247\) and on the same time abs_f_root value had been starting to approximate \(0\), then we can reveal that the estimated roots from each iteration are convergent to a specific value (that is \(1.324718\)). Based on that findings, we can define the convergence status of root which obtained by using Fixed Point method as like this.
root_fixedpoint_2_conv_status <-TRUE
Finding Root Using Newton Raphson Method With Initial Value\(x = 1\).
# root_newtonraphson_2_a_tableroot_newtonraphson_2_a_table <-data.frame(iteration =0:root_newtonraphson_2_a$much_iter,root = root_newtonraphson_2_a$root_complete,residual = root_newtonraphson_2_a$residu,abs_f_root = root_newtonraphson_2_a$abs_f_root )root_newtonraphson_2_a_table[rownames(root_newtonraphson_2_a_table) =="1","residual"] <-NA# insert root_newtonraphson_2_a_table# into a kable formatkable( root_newtonraphson_2_a_table,digits =10,caption ="Trace of Root of f(x) With Newton Raphson Method")
Trace of Root of f(x) With Newton Raphson Method
iteration
root
residual
abs_f_root
0
1.000000
NA
1.0000000000
1
1.500000
0.500000000
0.8750000000
2
1.347826
-0.152173913
0.1006821731
3
1.325200
-0.022625688
0.0020583619
4
1.324718
-0.000482225
0.0000009244
Convergence Status of Estimated Root of\(f(x)\).
Be noticed, since from iteration\(4\) the root value had been sticking in \(1.3247\) and on the same time abs_f_root value had been starting to approximate \(0\), then we can reveal that the estimated roots from each iteration are convergent to a specific value (that is \(1.324718\)). Based on that findings, we can define the convergence status of root which obtained by using Newton Raphson method (with initial value \(x = 1\)) as like this.
root_newtonraphson_2_a_conv_status <-TRUE
Finding Root Using Newton Raphson Method With Initial Value\(x = 1.75\).
# root_newtonraphson_2_b_tableroot_newtonraphson_2_b_table <-data.frame(iteration =0:root_newtonraphson_2_b$much_iter,root = root_newtonraphson_2_b$root_complete,residual = root_newtonraphson_2_b$residu,abs_f_root = root_newtonraphson_2_b$abs_f_root )root_newtonraphson_2_b_table[rownames(root_newtonraphson_2_b_table) =="1","residual"] <-NA# insert root_newtonraphson_2_b_table# into a kable formatkable( root_newtonraphson_2_b_table,digits =10,caption ="Trace of Root of f(x) With Newton Raphson Method")
Trace of Root of f(x) With Newton Raphson Method
iteration
root
residual
abs_f_root
0
1.750000
NA
2.6093750000
1
1.431298
-0.3187022901
0.5008775779
2
1.333961
-0.0973364185
0.0397597662
3
1.324797
-0.0091647034
0.0003353556
4
1.324718
-0.0000786249
0.0000000246
Convergence Status of Estimated Root of\(f(x)\).
Be noticed, since from iteration\(3\) the root value had been sticking in \(1.3247\) and on the same time abs_f_root value had been starting to approximate \(0\), then we can reveal that the estimated roots from each iteration are convergent to a specific value (that is \(1.324718\)). Based on that findings, we can define the convergence status of root which obtained by using Newton Raphson method (with initial value \(x = 1.75\)) as like this.
# root_secant_2_tableroot_secant_2_table <-data.frame(iteration =0:(root_secant_2$much_iter +1),root = root_secant_2$root_complete,residual = root_secant_2$residu,abs_f_root = root_secant_2$abs_f_root )root_secant_2_table[rownames(root_secant_2_table) =="1","residual"] <-NA# insert root_secant_2_table# into a kable formatkable( root_secant_2_table,digits =10,caption ="Trace of Root of f(x) With Secant Method")
Trace of Root of f(x) With Secant Method
iteration
root
residual
abs_f_root
0
1.000000
NA
1.0000000000
1
2.000000
1.0000000000
5.0000000000
2
1.166667
-0.8333333333
0.5787037037
3
1.253112
0.0864453665
0.2853630296
4
1.337206
0.0840944126
0.0538805867
5
1.323850
-0.0133563495
0.0036981154
6
1.324708
0.0008578401
0.0000427343
7
1.324718
0.0000100288
0.0000000346
Convergence Status of Estimated Root of\(f(x)\).
Be noticed, since from iteration\(6\) the root value had been sticking in \(1.3247\) and on the same time abs_f_root value had been starting to approximate \(0\), then we can reveal that the estimated roots from each iteration are convergent to a specific value (that is \(1.324718\)). Based on that findings, we can define the convergence status of root which obtained by using Secant method as like this.
# root_bisection_2_tableroot_bisection_2_table <-data.frame(iteration =1:root_bisection_2$much_iter,root = root_bisection_2$root_complete,residual = root_bisection_2$residu,abs_f_root = root_bisection_2$abs_f_root )root_bisection_2_table[rownames(root_bisection_2_table) =="1","residual"] <-NA# insert root_bisection_2_table# into a kable formatkable( root_bisection_2_table,digits =10,caption ="Trace of Root of f(x) With Bisection Method")
Trace of Root of f(x) With Bisection Method
iteration
root
residual
abs_f_root
1
1.500000
NA
0.8750000000
2
1.250000
-0.2500000000
0.2968750000
3
1.375000
0.1250000000
0.2246093750
4
1.312500
-0.0625000000
0.0515136719
5
1.343750
0.0312500000
0.0826110840
6
1.328125
-0.0156250000
0.0145759583
7
1.320312
-0.0078125000
0.0187106133
8
1.324219
0.0039062500
0.0021279454
9
1.326172
0.0019531250
0.0062088296
10
1.325195
-0.0009765625
0.0020366507
11
1.324707
-0.0004882812
0.0000465949
12
1.324951
0.0002441406
0.0009947910
13
1.324829
-0.0001220703
0.0004740388
14
1.324768
-0.0000610352
0.0002137072
15
1.324738
-0.0000305176
0.0000835524
16
1.324722
-0.0000152588
0.0000184779
17
1.324715
-0.0000076294
0.0000140587
18
1.324718
0.0000038147
0.0000022095
19
1.324717
-0.0000019073
0.0000059246
20
1.324718
0.0000009537
0.0000018576
21
1.324718
0.0000004768
0.0000001760
Convergence Status of Estimated Root of\(f(x)\).
Be noticed, since from iteration\(14\) the root value had been sticking in \(1.3247\) and on the same time abs_f_root value had been starting to approximate \(0\), then we can reveal that the estimated roots from each iteration are convergent to a specific value (that is \(1.324718\)). Based on that findings, we can define the convergence status of root which obtained by using Bisection method as like this.
From the table above we can know that from the estimation side, all methods produce the same root, that is \(\approx 1.324718\). From the iteration side, Bisection method do much more iterations than others, where it means that Bisection methods is more late in reaching the root, and Newton Rhapson method is faster in reaching the root. From the convergence side, all methods produce the result which are approximating a certain value. From the \(|f(\hat{x})|\) side, Newton Raphson (with initial value = \(1.75\)) and Secant method produce \(|f(\hat{x})|\) which are closest to \(0\), indicating that estimated roots as the result of these two methods are more precise. Therefore based on the simulation that we have done, we can conclude that for the precise result with low iteration time, we can consider to select Newton Rhapson method in finding root of \(f(x)\).
Explanation Why An Unsuitable Fixed-Point Rearrangement May Fail Even If The Equation Is Algebraically Equivalent.
From the given \(f(x) = x^3 - x - 1\) we can get another \(g(x) = x^3 - 1\). If we try to use this \(g(x)\) in function fixedpoint that we have made before, then we will find that the program will be error. One of the reasons why it happens is because the value of \(x_{i + 1} = g(x_i) = (x_{i + 1})^3 - 1\) which will decrease each time iteration increases. That power-three formulation makes \(g(x_{i})\) will always \(\leq 0\) even reach very little value (for the example \(-3.89017001 * 10^{8}\) at \(\pm \: 4th\) or \(5th\) iterations, with initial value \(=1\) ). It implies to the value of \(f(x = obtained \: root)\) which will be far from \(0\) as like as ilustrated below.
Therefore we must be careful when choosing \(g(x)\), as much as possible for not choosing form \(g(x) = x^{b} ...\), but prefer to choose form \(g(x) = x^{-b}\) or \(g(x) = x^{\frac{1}{b}}\), that is choosing form that will produce value which is convergent to a certain value.
(C). Exercise 3.
Consider \(f(x) = 4x^2 - 3x - 7\).
Use Newton-Rhapson with \(x_0\) to find a root.
Repeat with a different starting value to search for another root.
Verify the results by substitution into the original function.
Compare the estimates with a suitable uniroot interval for each root.
From the picture above we can know that the root of \(f(x)\) is close with \(-1\) and also close with \(2\), so we can use \(-1\) and also \(2\) to become initial value/range in estimating root of \(f(x)\). Other initial values actually is allowed to be used in finding root of \(f(x)\) as long as that initial value is not far from exact root.
Finding Root Using Newton Raphson Method With Initial Value\(x = 3\).
# root_fixedpoint_4_a_tableroot_fixedpoint_4_a_table <-data.frame(iteration =0:root_fixedpoint_4_a$much_iter,root = root_fixedpoint_4_a$root_complete,residual = root_fixedpoint_4_a$residu,abs_f_root = root_fixedpoint_4_a$abs_f_root )root_fixedpoint_4_a_table[rownames(root_fixedpoint_4_a_table) =="1","residual"] <-NA# insert root_fixedpoint_4_a_table# into a kable formatkable( root_fixedpoint_4_a_table,digits =10,caption ="Trace of Root of f(x) With Fixed Point Method")
Trace of Root of f(x) With Fixed Point Method
iteration
root
residual
abs_f_root
0
2.000000
NA
0.5578118973
1
1.144921
-0.8550794073
0.1829139049
2
1.374719
0.2297981894
0.0653384793
3
1.287768
-0.0869504968
0.0229750861
4
1.317697
0.0299290824
0.0081346699
5
1.307022
-0.0106755532
0.0028737033
6
1.310783
0.0037613948
0.0010160148
7
1.309452
-0.0013310988
0.0003591149
8
1.309922
0.0004703283
0.0001269437
9
1.309756
-0.0001662758
0.0000448718
10
1.309815
0.0000587724
0.0000158614
11
1.309794
-0.0000207753
0.0000056067
12
1.309802
0.0000073436
0.0000019819
13
1.309799
-0.0000025958
0.0000007005
Finding Root Using Fixed Point Method With\(g_{2}(x) = x + log(x) - e^{-x}\).
# root_fixedpoint_4_b_tableroot_fixedpoint_4_b_table <-data.frame(iteration =0:root_fixedpoint_4_b$much_iter,root = root_fixedpoint_4_b$root_complete,residual = root_fixedpoint_4_b$residu,abs_f_root = root_fixedpoint_4_b$abs_f_root )root_fixedpoint_4_b_table[rownames(root_fixedpoint_4_b_table) =="1","residual"] <-NA# insert root_fixedpoint_4_b_table# into a kable formatkable( root_fixedpoint_4_b_table,digits =10,caption ="Trace of Root of f(x) With Fixed Point Method")
From the visualization above we can see that curve of iterations using \(g_1(x) = e^{e^{-x}}\) seems to descend and curve of iterations using \(g_2(x) = x + log(x) - e^{-x}\) seemes to ascend. It means that by using \(g_1(x) = e^{e^{-x}}\) we will obtain a certain value as the root of \(f(x)\), meanwhile by using \(g_2(x) = x + log(x) - e^{-x}\) we won’t obtain a (fixed) certain value (a.k.a we won’t obtain the root).
The reason why by using \(g_1(x)\) we can obtain root meanwhile by using \(g_2(x)\) we won’t reach the root is back to the nature of each function.
If we use \(g_1(x) = e^{e^{-x}}\) then when we substitute with a certain \(x\), let ’s say we take \(x = -1\), then we will obtain \(g_1(-1) \approx 15.15426\), and we take that \(15.15426\) to be \(x\), then we will obtain \(g_1(15.15426) \approx 1\), and so on until we will find a certain \(x\) with value \(\approx 1.3098\), where \(f(1.3098) \approx 0\).
It is different if we use \(g_2(x) = x + log(x) - e^{-x}\), it means domain for this function must be \(x > 0\), so it means that part \(x \: + \: log(x)\) must always be positive, and part \(e^{-x}\) will approximate to \(0\) as the number of iterations increases. It means that \(g_2(x)\) does not approximate to a (fixed) certain value which also means we won’t obtain the root of \(f(x)\).
(E). Exercise 5
Modify the bisection() function so that it:
Prints a clear message if the starting interval does not bracket a root.
Returns a table containing the midpoint and resiudal \(|f(x_m)|\) at every iteration.
Stops using both an interval-width criterion and a function-residual critertion.