{"id":199,"date":"2017-09-13T11:11:09","date_gmt":"2017-09-13T14:11:09","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=199"},"modified":"2017-09-13T11:11:09","modified_gmt":"2017-09-13T14:11:09","slug":"trapz2-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/trapz2-f\/","title":{"rendered":"trapz2.f"},"content":{"rendered":"<pre>c&lt;html&gt;\r\nc&lt;head&gt;&lt;title&gt;trapz2.f&lt;\/title&gt;&lt;\/head&gt;\r\nc&lt;body&gt;\r\nc&lt;pre&gt;\r\n      module commdata\r\n         integer ntrys, nint1,npoints,np,dbl\r\n         parameter (ntrys=8,nint1=10,npoints=nint1*2**(ntrys-1)+1 )\r\n         parameter (dbl = selected_real_kind(13,200))\r\n         real(dbl) x(npoints),y(npoints)\r\n         real(dbl) ansreal,ansnum\r\nc&lt;a name=\"em\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      end module commdata\r\nc&lt;\/a&gt;&lt;\/font&gt;\r\n      program trapezoid\r\nc\r\nc    The use statements must be the first thing found after the PROGRAM\r\nc    statement\r\nc\r\n      use commdata\r\nc\r\nc    Test Trapezoidal Rule of Integration\r\nc\r\nc   John Mahaffy 5\/10\/96\r\nc\r\n      implicit none\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 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\n      end\r\n      subroutine setcurve\r\nc\r\nc    Use statements must be the first thing found after the SUBROUTINE\r\nc    statement\r\nc\r\n      use commdata\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 5\/10\/96\r\nc\r\n      implicit none\r\nc\r\n      integer i\r\n      real(dbl) 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\n      ansreal=cos(xlow)-cos(xhigh)\r\n      return\r\n      end\r\nc\r\n      subroutine integrate\r\nc&lt;a name=\"use\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      use commdata\r\nc&lt;\/font&gt;&lt;\/a&gt;\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 5\/10\/96\r\nc\r\n      implicit none\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(dbl) sum2, esterr\r\nc&lt;a name=1&gt;&lt;font color=FF0000&gt;\r\n      ansnum=0.5*dot_product(y(1:np-1)+y(2:np),x(2:np)-x(1:np-1))\r\nc&lt;\/font&gt;\r\nc\r\nc   The following only works if np is an odd integer\r\nc\r\n      sum2 = 0.5*dot_product(y(1:np-1:2)+y(3:np:2),\r\n     &amp;                       x(3:np:2)-x(1:np-1:2))\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\nc&lt;\/pre&gt;\r\nc&lt;\/body&gt;\r\nc&lt;\/html&gt;\r\n      subroutine compare\r\nc\r\nc    The following USE only picks up information about ANSNUM and\r\nc    ANSREAL from the MODULE named COMMDATA, ignores other information\r\nc    If I used the variable names \"x\" or \"y\" here they would be treated\r\nc    as local variables, unrelated to the \"x\" and \"y\" defined in\r\nc    COMMDATA\r\nc\r\nc   John Mahaffy 5\/10\/96\r\nc\r\n      use commdata , only : ansnum, ansreal, dbl\r\nc\r\nc  Compare results of the numerical integration with the actual result\r\nc\r\n      implicit none\r\n      real (dbl) 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;trapz2.f&lt;\/title&gt;&lt;\/head&gt; c&lt;body&gt; c&lt;pre&gt; module commdata integer ntrys, nint1,npoints,np,dbl parameter (ntrys=8,nint1=10,npoints=nint1*2**(ntrys-1)+1 ) parameter (dbl = selected_real_kind(13,200)) real(dbl) x(npoints),y(npoints) real(dbl) ansreal,ansnum c&lt;a name=&#8221;em&#8221;&gt;&lt;font color=&#8221;FF0000&#8243;&gt; end module commdata c&lt;\/a&gt;&lt;\/font&gt; program trapezoid c c The use statements must be the first thing found after the PROGRAM c statement c use commdata c c Test Trapezoidal Rule of Integration [&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-199","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/199","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=199"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/199\/revisions"}],"predecessor-version":[{"id":200,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/199\/revisions\/200"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}