{"id":508,"date":"2017-09-14T13:14:11","date_gmt":"2017-09-14T16:14:11","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=508"},"modified":"2017-09-14T13:14:11","modified_gmt":"2017-09-14T16:14:11","slug":"traptoltol-m","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/traptoltol-m\/","title":{"rendered":"traptoltol.m"},"content":{"rendered":"<pre>function [z, n] = traptol(func,a,b,tol)\r\n% Routine for trapezoidal integration to specified tolerance.\r\n%\r\n% USAGE:  [z, n] = traptol('function',a,b,tol)\r\n%\r\n% input:  function = name of external function file.  This file\r\n%             must be able to receive a vector of x data as input \r\n%\t      and produce a vector of y data as output\r\n%         a, b     = limits of integration\r\n%         tol      = absolute error tolerance in answer\r\n% output: z        = value of integral of function between a and b\r\n%         n        = number of intervals required to obtained desired accuracy\r\n\r\n% NOTE: in this routine n refers to the number of segments in the\r\n%   interval from a to b\r\n\r\n% first integral using 2 segments\r\nn = 2;\r\nh = (b-a)\/n;\r\nx = linspace(a,b,n+1);\r\ny = feval(func,x);\r\nz1 = h*trapzeq(y);\r\n\r\n\r\n\r\nabserror = Inf;\r\n% start looping with doubled N\r\nwhile abserror &gt; tol\r\n  n = 2*n;\r\n  h = (b-a)\/n;\r\n  x = linspace(a,b,n+1);\r\n  y = feval(func,x);\r\n  z2 = h*trapzeq(y);\r\n  abserror = abs(z2 - z1);\r\n  z1 = z2; % store this for next loop\r\nend\r\n\r\nz = z2;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>function [z, n] = traptol(func,a,b,tol) % Routine for trapezoidal integration to specified tolerance. % % USAGE: [z, n] = traptol(&#8216;function&#8217;,a,b,tol) % % input: function = name of external function file. This file % must be able to receive a vector of x data as input % and produce a vector of y data as output [&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-508","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/508","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=508"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/508\/revisions"}],"predecessor-version":[{"id":509,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/508\/revisions\/509"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}