{"id":195,"date":"2017-09-13T11:08:06","date_gmt":"2017-09-13T14:08:06","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=195"},"modified":"2017-09-13T11:08:06","modified_gmt":"2017-09-13T14:08:06","slug":"trapezoid-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/trapezoid-f\/","title":{"rendered":"trapezoid.f"},"content":{"rendered":"<pre>c&lt;html&gt;\r\nc&lt;head&gt;&lt;title&gt;trapezoid.f&lt;\/title&gt;&lt;\/head&gt;\r\nc&lt;body&gt;\r\nc&lt;pre&gt;\r\n      program trapezoid\r\nc\r\nc    Test Trapezoidal Rule of Integration\r\nc\r\nc      John Mahaffy 4\/1\/95\r\nc\r\n      implicit none\r\nc\r\nc   PARAMETERS\r\nc    ntrys - Number of integrations, each with half the x step of the last\r\nc    nint1 - Number of steps between lowest and highest x values\r\nc    npoints - Largest number of points evaluated for use in the integration\r\nc\r\nc   Variables\r\nc    x   -   x values at which the function is evaluated\r\nc    y   -   values of the function for corresponding values of x\r\nc    np  -   number of points currently used in x and y\r\nc    ansreal - Actual Value of the integral\r\nc    ansnum  - Value of the integral obtained from a Trapezoidal Rule\r\nc\r\n      integer ntrys,nint1,npoints\r\n      parameter (ntrys=8,nint1=10,npoints=nint1*2**(ntrys-1)+1 )\r\nc&lt;a name=\"com\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      common x(npoints),y(npoints)\r\n      common\/misc\/np\r\n      common\/answer\/ansreal,ansnum\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n      real x,y,ansreal,ansnum\r\n      integer np\r\n      integer i\r\n      do 10 i=1,ntrys\r\n         np=nint1*2**(i-1)+1\r\n         call setcurve\r\n         call integrate\r\n         call compare\r\n  10  continue\r\n      stop\r\nc&lt;a name=\"end\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      end\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n      subroutine setcurve\r\nc\r\nc    Set up a Curve and range for integration\r\nc    Here we will integrate sin(x) from x=0 to x=3.0\r\nc\r\nc      John Mahaffy 4\/1\/95\r\nc\r\n      implicit none\r\n      integer ntrys,nint1,npoints\r\n      parameter (ntrys=8,nint1=10,npoints=nint1*2**(ntrys-1)+1 )\r\n      common x(npoints),y(npoints)\r\n      common\/misc\/np\r\n      common\/answer\/ansreal,ansnum\r\n      real x,y,ansreal,ansnum\r\n      integer np\r\nc\r\n      integer i\r\n      real dx,xlow,xhigh\r\n      data xlow,xhigh\/0.0,3.0\/\r\nc\r\n      dx=(xhigh-xlow)\/(np-1)\r\n      x(1)=xlow\r\n      y(1)=sin(x(1))\r\n      do 10 i=2,np\r\n         x(i)=x(i-1)+dx\r\n         y(i)=sin(x(i))\r\n  10     continue\r\nc&lt;a name=1&gt;&lt;font color=FF0000&gt;\r\n      ansreal=cos(xlow)-cos(xhigh)\r\nc&lt;\/font&gt;\r\n      return\r\n      end\r\n      subroutine integrate\r\nc\r\nc    Use Trapezoidal Rule to Integrate the area under the curve\r\nc    specified by the data points in x and y\r\nc\r\nc      John Mahaffy 4\/1\/95\r\nc\r\n      implicit none\r\n      integer ntrys,nint1,npoints\r\n      parameter (ntrys=8,nint1=10,npoints=nint1*2**(ntrys-1)+1 )\r\n      common x(npoints),y(npoints)\r\n      common\/misc\/np\r\n      common\/answer\/ansreal,ansnum\r\n      real x,y,ansreal,ansnum\r\n      integer np\r\nc\r\nc   Local Variables\r\nc\r\nc    esterr   -   estimated error for Trapizoidal integration\r\nc    sum2     -   Trapizoidal integration using every other available point\r\nc\r\n      integer i\r\n      real sum2, esterr\r\n      ansnum=0.0\r\n      do 10 i=1,np-1\r\n   10    ansnum=ansnum+.5*(y(i)+y(i+1))*(x(i+1)-x(i))\r\nc\r\nc   The following only works if np is an odd integer\r\nc\r\n      sum2=0.0\r\nc&lt;a name=\"do\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      do 20 i=1,np-1,2\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n   20    sum2=sum2+.5*(y(i)+y(i+2))*(x(i+2)-x(i))\r\n      esterr=(sum2-ansnum)*.333333\r\n      write(6,2000) np,ansnum,esterr\r\n 2000 format (' For ',i4,' points the integral is ',1p,e12.5,\r\n     &amp; ', Estimated Error=',e10.2)\r\n      return\r\n      end\r\n      subroutine compare\r\nc\r\nc  Compare results of the numerical integration with the actual result\r\nc\r\nc      John Mahaffy 4\/1\/95\r\nc\r\n      implicit none\r\n      common\/answer\/ansreal,ansnum\r\n      real ansreal,ansnum\r\n      real error\r\n      error=ansnum-ansreal\r\n      write(6,2001) error\r\n 2001 format(' Actual Error = ',1p,e10.2)\r\n      return\r\n      end\r\nc&lt;\/pre&gt;\r\nc&lt;\/body&gt;\r\nc&lt;\/html&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>c&lt;html&gt; c&lt;head&gt;&lt;title&gt;trapezoid.f&lt;\/title&gt;&lt;\/head&gt; c&lt;body&gt; c&lt;pre&gt; program trapezoid c c Test Trapezoidal Rule of Integration c c John Mahaffy 4\/1\/95 c implicit none c c PARAMETERS c ntrys &#8211; Number of integrations, each with half the x step of the last c nint1 &#8211; Number of steps between lowest and highest x values c npoints &#8211; Largest [&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-195","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/195","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=195"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/195\/revisions"}],"predecessor-version":[{"id":196,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/195\/revisions\/196"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}