{"id":215,"date":"2017-09-13T11:15:59","date_gmt":"2017-09-13T14:15:59","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=215"},"modified":"2017-09-13T11:15:59","modified_gmt":"2017-09-13T14:15:59","slug":"quadfit-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/quadfit-f\/","title":{"rendered":"quadfit.f"},"content":{"rendered":"<pre>      subroutine quadfit (xd,yd,ndata,c)\r\n      implicit none\r\nc\r\nc       Take corresponding data points from the arrays xd and yd and fit\r\nc       them with the following equation:\r\nc\r\nc       y = c(1) + c(2) * x + c(3) * x**2\r\nc\r\n       real xd(ndata),yd(ndata),aa(3,3),c(3),fs,suma,sumb,sqrt,rsid\r\n       integer ipvt(3),ir,is,ij,ndata, info\r\nc\r\nc    Input Arguments:\r\nc      xd   -   x values for data points\r\nc      yd   -   y valuess for data point pairs\r\nc      ndata -  number of data points\r\nc\r\nc    Output Arguements:\r\nc      c    -   array containing the three coefficients in the 2nd order\r\nc               polynomial that provide the \"best\" fit to the data from a\r\nc               least squares method.  Note that it also temporarily holds\r\nc               the values of the right hand sides of each Least Squares\r\nc               equation.\r\nc    Other Key Variables:\r\nc      aa   -   matrix containing coefficients of the system of equations\r\nc               generated by the least squares method\r\nc      suma -   a variable that tallies the sum that is needed to generate\r\nc               each element of aa.\r\nc      sumb -   a variable that tallies the sum that is needed for the right\r\nc               hand side of each Least Squares equation.\r\nc      ir   -   an index that is used to keep track of the equation number\r\nc               within the system of equations .\r\nc      is   -   an index used to track the coefficient number within a given\r\nc               Least Squares equation.\r\nc\r\nc\r\nc    DO loop 55 generates terms for each of the 3 Least Squares Equations\r\nc\r\n      do 55 ir=1,3\r\nc\r\nc       DO loop 45 generates the right hand side for a given equation\r\nc\r\n         sumb=0.\r\n         do 45 ij=1,ndata\r\n  45        sumb=sumb+yd(ij)*xd(ij)**(ir-1)\r\n         c(ir)=sumb\r\nc\r\nc       DO loop 50 generates the coefficients a given equation\r\nc\r\n         do 50 is=1,3\r\n            suma=0.\r\n            do 52 ij=1,ndata\r\n  52           suma=suma+xd(ij)**(is-1)*xd(ij)**(ir-1)\r\n  50        aa(ir,is)=suma\r\n  55     continue\r\nc\r\nc    Solve the Least Squares Equations\r\nc\r\n            call sgefa(aa,3,3,ipvt,info)\r\n            call sgesl(aa,3,3,ipvt,c ,0)\r\nc\r\nc    Calculate a measure of mean error between the data and the curve\r\nc\r\n            rsid=0.\r\n            do 65 ir=1,ndata\r\n               fs=0.\r\n               do 60 is=1,3\r\n   60             fs=fs+c(is)*xd(ir)**(is-1)\r\n   65          rsid=rsid+(yd(ir)-fs)**2\r\n            rsid=sqrt(rsid\/float(ndata-1))\r\n            write(6,2001) rsid\r\n 2001       format(' Fit to 2nd order polynomial has a mean error of',\r\n     $             1p,e12.5)\r\n      return\r\n      end<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>subroutine quadfit (xd,yd,ndata,c) implicit none c c Take corresponding data points from the arrays xd and yd and fit c them with the following equation: c c y = c(1) + c(2) * x + c(3) * x**2 c real xd(ndata),yd(ndata),aa(3,3),c(3),fs,suma,sumb,sqrt,rsid integer ipvt(3),ir,is,ij,ndata, info c c Input Arguments: c xd &#8211; x values for data [&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-215","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/215","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=215"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/215\/revisions"}],"predecessor-version":[{"id":216,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/215\/revisions\/216"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}