{"id":447,"date":"2017-09-14T12:26:08","date_gmt":"2017-09-14T15:26:08","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=447"},"modified":"2017-09-14T12:26:08","modified_gmt":"2017-09-14T15:26:08","slug":"bisect-m","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/bisect-m\/","title":{"rendered":"bisect.m"},"content":{"rendered":"<pre>% Demonstration of Bisection Root Finding of a function\r\n%\r\n% The function is defined in the file 'fcn.m' as follows:\r\n%      function y = fcn(x)\r\n%      y = 9.8 * 68.1 * (1-exp(-10*x\/68.1))\/x - 40;\r\n\r\nclear;   \r\n\r\n      xl = input ('Enter lower bound of root bracket:  ');\r\n      xu = input ('Enter upper bound of root bracket:  ');\r\nmaxerror = input ('Enter maximum error (percent):      ');\r\n   maxit = input ('Enter maximum number of iterations: ');\r\n\r\nfplot('fcn',[xl xu]); grid on; hold on;\r\n\r\ncount = 0;          % iteration counter\r\nactual_error = 1;   % to force entry to while loop\r\n\r\nfprintf('\\n  #         xl         xu         xr      error\\n\\n');\r\n\r\n% main loop until interval width small enough\r\n\r\nwhile (actual_error &gt; maxerror) &amp; (count &lt; maxit)\r\n\r\n  count = count + 1;\r\n  xr = (xl + xu)\/2;\r\n  plot(xr,fcn(xr),'ro');\r\n\r\n  if xr ~= 0                            % ~= not equal\r\n    actual_error = abs((xu - xl)\/(xu + xl)) * 100;\r\n  end\r\n\r\n  fprintf('%3g %10g %10g %10g %10.4f\\n',count,xl,xu,xr,actual_error)\r\n\r\n  test = fcn(xl) * fcn(xr);  % form test product\r\n\r\n  if test == 0\r\n    actual_error = 0;\r\n  elseif test &lt; 0\r\n    xu = xr;      % root is below xr\r\n  else        % i.e. test &gt; 0\r\n    xl = xr;      % root is above xr\r\n  end\r\n\r\nend\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>% Demonstration of Bisection Root Finding of a function % % The function is defined in the file &#8216;fcn.m&#8217; as follows: % function y = fcn(x) % y = 9.8 * 68.1 * (1-exp(-10*x\/68.1))\/x &#8211; 40; clear; xl = input (&#8216;Enter lower bound of root bracket: &#8216;); xu = input (&#8216;Enter upper bound of root [&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-447","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/447","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=447"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/447\/revisions"}],"predecessor-version":[{"id":448,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/447\/revisions\/448"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}