{"id":451,"date":"2017-09-14T12:26:57","date_gmt":"2017-09-14T15:26:57","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=451"},"modified":"2017-09-14T12:26:57","modified_gmt":"2017-09-14T15:26:57","slug":"falspos-m","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/falspos-m\/","title":{"rendered":"falspos.m"},"content":{"rendered":"<pre>% Demonstration of Root Finding using False Position\r\n%\r\n% The function is defined in the file 'fcn.m'\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\nrel_error = 1;      % to force entry into while loop\r\nxr = xu;            % require starting value in loop below\r\n\r\nfprintf('\\n  #         xl         xu         xr      error\\n\\n');\r\n\r\n% main loop until change between iterations small enough\r\n\r\nwhile (rel_error &gt; maxerror) &amp; (count &lt; maxit) \r\n  count = count + 1;\r\n  xrold = xr;\r\n\r\n  xr = xu - fcn(xu)*(xu-xl)\/(fcn(xu)-fcn(xl));\r\n  plot(xr,fcn(xr),'ro');\r\n\r\n  if xr ~= 0\r\n    rel_error = abs((xr - xrold)\/xr) * 100;\r\n  end\r\n  fprintf('%3g %10g %10g %10g %10.4f\\n',count,xl,xu,xr,rel_error)\r\n\r\n  test = fcn(xl) * fcn(xr);  % form test product\r\n\r\n  if test == 0\r\n    rel_error = 0;  % root is at xr\r\n  elseif test &lt; 0\r\n    xu = xr;        % root is below xr\r\n  else\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 Root Finding using False Position % % The function is defined in the file &#8216;fcn.m&#8217; % 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 bracket: &#8216;); maxerror [&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-451","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/451","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=451"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/451\/revisions"}],"predecessor-version":[{"id":452,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/451\/revisions\/452"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}