{"id":99,"date":"2015-06-19T23:23:30","date_gmt":"2015-06-19T23:23:30","guid":{"rendered":"https:\/\/mgric.wordpress.com\/?p=99"},"modified":"2015-11-05T00:46:07","modified_gmt":"2015-11-05T00:46:07","slug":"one-dimensional-search-method-newtons-method-part-3","status":"publish","type":"post","link":"https:\/\/marcelloricottone.com\/blog\/2015\/06\/19\/one-dimensional-search-method-newtons-method-part-3\/","title":{"rendered":"One Dimensional Search Method: Newton&#8217;s Method Part 3"},"content":{"rendered":"<p>Unlike GSS and FS, Newton&#8217;s method has different limitations and restrictions. However, before we jump in lets look at a harder more elaborate function. Part2 goes over a too simple function for the sake of consistency, but lets take a function say: f(x) = x^4+6x^3+x^2-2x +cos(x) . This function is plotted below.<\/p><img loading=\"lazy\" decoding=\"async\" class=\"  wp-image-101 aligncenter\" src=\"http:\/\/marcelloricottone.com\/blog\/wp-content\/uploads\/2015\/06\/screen-shot-2015-06-19-at-6-37-08-pm.png?w=300\" alt=\"Screen Shot 2015-06-19 at 6.37.08 PM\" width=\"403\" height=\"312\" srcset=\"https:\/\/marcelloricottone.com\/blog\/wp-content\/uploads\/2015\/06\/screen-shot-2015-06-19-at-6-37-08-pm.png 642w, https:\/\/marcelloricottone.com\/blog\/wp-content\/uploads\/2015\/06\/screen-shot-2015-06-19-at-6-37-08-pm-300x232.png 300w\" sizes=\"auto, (max-width: 403px) 100vw, 403px\" \/><\/p>As you can see we have two minimums so we can see how our method behaves. I am going to skip the step by step and just show the results of the method. We will choose our fist point at -8. This produces the following graph\u00a0with the points different colors.<\/p><a href=\"http:\/\/marcelloricottone.com\/blog\/wp-content\/uploads\/2015\/06\/screen-shot-2015-06-19-at-6-51-12-pm.png\"><img loading=\"lazy\" decoding=\"async\" class=\"  wp-image-104 aligncenter\" src=\"http:\/\/marcelloricottone.com\/blog\/wp-content\/uploads\/2015\/06\/screen-shot-2015-06-19-at-6-51-12-pm.png?w=300\" alt=\"Screen Shot 2015-06-19 at 6.51.12 PM\" width=\"480\" height=\"386\" srcset=\"https:\/\/marcelloricottone.com\/blog\/wp-content\/uploads\/2015\/06\/screen-shot-2015-06-19-at-6-51-12-pm.png 641w, https:\/\/marcelloricottone.com\/blog\/wp-content\/uploads\/2015\/06\/screen-shot-2015-06-19-at-6-51-12-pm-300x241.png 300w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a>I had to make this graph a little bigger so you can see whats going on. Each point represents a step in our method. This method took 5 steps to get to our minimum (not including the starting point). Newton&#8217;s Method produced a minimum of -4.3462 which is close to the actual minimum, -4.34613. With only 5 iterations this is impressive method. Lets try a new initial point,5. This produces the following.<\/p><a href=\"http:\/\/marcelloricottone.com\/blog\/wp-content\/uploads\/2015\/06\/screen-shot-2015-06-19-at-7-00-50-pm.png\"><img loading=\"lazy\" decoding=\"async\" class=\"  wp-image-106 aligncenter\" src=\"http:\/\/marcelloricottone.com\/blog\/wp-content\/uploads\/2015\/06\/screen-shot-2015-06-19-at-7-00-50-pm.png?w=300\" alt=\"Screen Shot 2015-06-19 at 7.00.50 PM\" width=\"513\" height=\"405\" srcset=\"https:\/\/marcelloricottone.com\/blog\/wp-content\/uploads\/2015\/06\/screen-shot-2015-06-19-at-7-00-50-pm.png 641w, https:\/\/marcelloricottone.com\/blog\/wp-content\/uploads\/2015\/06\/screen-shot-2015-06-19-at-7-00-50-pm-300x237.png 300w\" sizes=\"auto, (max-width: 513px) 100vw, 513px\" \/><\/a>Uh oh. It looks like our method converged to the wrong point. Like FS and GSS, Netwon&#8217;s\u00a0will find a minimum on the interval you choose however, this minimum might not be a global minimum. Local vs global minimum is a major\u00a0issue with\u00a0all three ODSM. In this case, Newton&#8217;s method got caught in a saddle-like point.<\/p>Another more obvious limitation stems from the method itself. We need to be able to find the second derivative of our function. If there is no second derivative, there is no method. Well mathematicians don&#8217;t exactly take no for an answer. The Secant method was developed to remedy this. The Secant method is basically a modified Newton&#8217;s method that does not require a second derivative, only the first.<\/p>The last limitation involves our initial conditions like with GSS and FS. Our initial value for Newton&#8217;s method greatly determines the effectiveness. This is evidenced by the two above graphs which show how sensitive the method is.<\/p>I hope you understand Newtons method a little better. You can experiment more if you like i have copied the code below.<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\n%array to get values of our function\nz = -8:.001:5;&lt;\/code&gt;\n\n% our function x^4+8x^3-2x +cos(x)\nl = z.^4+6*z.^3+z.^2-2*z+cos(z);\n\ntol = 1;\n%initialize arrays to store step values\nx = zeros(1,10);\ny = zeros(1,10);\n%initial guess\nx(1)=5;\ny(1) = x(1).^4+6*x(1).^3+x(1).^2-2*x(1)+cos(x(1));\ni=2;\nwhile tol &amp;gt;0.005 %tolerance stop condition\n     %first derivative\n     dx = 4*x(i-1).^3+18*x(i-1).^2+2*x(i-1)-2-sin(x(i-1));\n     %second derivative\n     d2x = 12*x(i-1).^2+36*x(i-1)+2-cos(x(i-1));\n     %newtons method step\n     x(i) = x(i-1)-(dx\/d2x);\n     y(i)= x(i).^4+6*x(i).^3+x(i).^2-2*x(i)+cos(x(i));\n\n     tol = abs(x(i)-x(i-1));\n     i= i +1;\nend\n\nx\n%plot our results\nplot(z,l,x(1),y(1),'g*',x(4),y(4),'g*',x(2),y(2),'c*',x(3),y(3),'r*',x(5),y(5),'c*',x(6),y(6),'r*',x(7),y(7),'g*',x(8),y(8),'g*',x(9),y(9),'c*',x(10),y(10),'r*')\n\ntitle('Newtons Method example 2 ')\nxlabel('x')\nylabel('y')\n<\/pre><p>-Marcello<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unlike GSS and FS, Newton&#8217;s method has different limitations and restrictions. However, before we jump in lets look at a harder more elaborate function. Part2 goes over a too simple function for the sake of consistency, but lets take a function say: f(x) = x^4+6x^3+x^2-2x +cos(x) . This function is plotted below.As you can see&hellip; <\/p>\n<p class=\"toivo-read-more\"><a href=\"https:\/\/marcelloricottone.com\/blog\/2015\/06\/19\/one-dimensional-search-method-newtons-method-part-3\/\" class=\"more-link\">Read more <span class=\"screen-reader-text\">One Dimensional Search Method: Newton&#8217;s Method Part 3<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,2],"tags":[],"class_list":{"0":"post-99","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-allposts","7":"category-odsm","8":"category-opt","9":"entry"},"_links":{"self":[{"href":"https:\/\/marcelloricottone.com\/blog\/wp-json\/wp\/v2\/posts\/99","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/marcelloricottone.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/marcelloricottone.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/marcelloricottone.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/marcelloricottone.com\/blog\/wp-json\/wp\/v2\/comments?post=99"}],"version-history":[{"count":1,"href":"https:\/\/marcelloricottone.com\/blog\/wp-json\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":294,"href":"https:\/\/marcelloricottone.com\/blog\/wp-json\/wp\/v2\/posts\/99\/revisions\/294"}],"wp:attachment":[{"href":"https:\/\/marcelloricottone.com\/blog\/wp-json\/wp\/v2\/media?parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/marcelloricottone.com\/blog\/wp-json\/wp\/v2\/categories?post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/marcelloricottone.com\/blog\/wp-json\/wp\/v2\/tags?post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}