{"id":161,"date":"2017-09-13T10:40:39","date_gmt":"2017-09-13T13:40:39","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=161"},"modified":"2017-09-13T10:40:39","modified_gmt":"2017-09-13T13:40:39","slug":"secant-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/secant-f\/","title":{"rendered":"secant.f"},"content":{"rendered":"<pre>c&lt;html&gt;\r\nc&lt;head&gt;&lt;title&gt;secant.f&lt;\/title&gt;&lt;\/head&gt;\r\nc&lt;body&gt;\r\nc&lt;pre&gt;\r\n      program secant\r\nc\r\nc   Use a Secant iteration to solve the equation\r\nc\r\nc     x**3+x-10=0\r\nc\r\nc    x    -     current approximation to the solution\r\nc    f(x) -     x**3+x-10\r\nc    dfdx(x) -  derivative of f with respect to x\r\nc    xm1   -    previous guess for solution\r\nc    eps   -    convergence criterion\r\nc    dx    -    change in solution approximation\r\nc    it    -    number of iterations\r\nc    itmax -    maximum number of iterations\r\nc\r\nc &lt;a name=\"implicit\"&gt;&lt;font color=\"FF0000\"&gt; \r\n      implicit none\r\nc &lt;\/font&gt;&lt;\/a&gt;\r\n      integer it,itmax,r8\r\n      parameter (r8=selected_real_kind(14,100))\r\n      real(r8) x,f,dfdx,xo,eps,fx,dx,x0,xm1,fxm1,xm2,fxm2\r\nc\r\nc     Use fortran statement functions to define f and its derivative\r\nc     Note that these statements must appear before other executable\r\nc     statements\r\nc\r\n      f(x)=x**3+x-10.\r\n      dfdx(x)=3*x**2+1.\r\nc\r\nc     Now start executable fortran statements\r\nc\r\n      eps=1.e-6\r\n      itmax=10\r\n      write(*,*) 'Secant Iteration to find a solution to x**3+x-10=0'\r\n      Write(*,'(a)',advance='no')'Initial guess for the solution: '\r\n      read *, x0\r\nc\r\nc   Set the two starter points for the Secant Iteration\r\nc\r\n      x=x0\r\n      xm1=.999*x\r\n      fxm1=f(xm1)\r\nc\r\nc   Secant Iteration\r\nc\r\n      do 5 it=1,itmax\r\n         xm2=xm1\r\n         fxm2=fxm1\r\n         xm1=x\r\n         fxm1=f(xm1)\r\n         dx = -fxm1*(xm1-xm2)\/(fxm1-fxm2)\r\n         x=xm1+dx\r\n         print *, ' x = ',x,',  f(xm1) = ',fxm1, ', dx = ',dx\r\nc        &lt;a name=abs&gt; &lt;font color = FF0000&gt;\r\n         if(abs(dx).lt.eps*abs(x)) go to 10\r\nc\t   ^^^^^^^^^^^^^^^^^^^^^^&lt;\/font&gt;&lt;\/a&gt;\r\n  5      continue\r\n         write(6,*)'Secant Iteration Failed to Converge'\r\n 10   x=x0\r\nc\r\nc   For comparison here is a Newton Iteration\r\nc\r\n      write(6,*) 'For comparison here is a Newton Iteration'\r\n      do 15 it=1,itmax\r\n         xo=x\r\n         fx=f(xo)\r\n         dx = -fx\/dfdx(xo)\r\n         x=xo+dx\r\n         print *, ' x = ',x,',  f(x) = ',fx, ', dx = ',dx\r\nc&lt;a name=\"go\"&gt;&lt;font color=\"FF0000\"&gt;\r\n         if(abs(dx).lt.eps*abs(x)) go to 20\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n  15     continue\r\n         write(6,*)'Newton Iteration Failed to Converge'\r\n  20  stop\r\n      end\r\nc&lt;\/pre&gt;\r\nc&lt;\/body&gt;\r\nc&lt;\/html&gt;\r\n\r\n\r\n\r\n\r\n\r\n\r\ncc<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>c&lt;html&gt; c&lt;head&gt;&lt;title&gt;secant.f&lt;\/title&gt;&lt;\/head&gt; c&lt;body&gt; c&lt;pre&gt; program secant c c Use a Secant iteration to solve the equation c c x**3+x-10=0 c c x &#8211; current approximation to the solution c f(x) &#8211; x**3+x-10 c dfdx(x) &#8211; derivative of f with respect to x c xm1 &#8211; previous guess for solution c eps &#8211; convergence criterion c [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[],"tags":[],"class_list":["post-161","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/comments?post=161"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/161\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/161\/revisions\/162"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}