{"id":458,"date":"2017-09-14T12:30:27","date_gmt":"2017-09-14T15:30:27","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=458"},"modified":"2017-09-14T12:30:27","modified_gmt":"2017-09-14T15:30:27","slug":"secant-m","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/secant-m\/","title":{"rendered":"secant.m"},"content":{"rendered":"<pre>% Root finding using Secant method\r\n%\r\n% The function is defined in another script file as follows:\r\n% (Note that this won't accept vector inputs)\r\n%\r\n%   function y = fcn(x)\r\n%       y = x^4 - 5*x^3 - 124*x^2 + 380*x + 1200;\r\nclear; clf; \r\n\r\n% First, plot the function to estimate the root location\r\nfplot('fcn',[1 20])\r\nhold on\r\n\r\n% now proceed with finding a root:\r\n\r\nx1 = input('Enter first guess of root location: ');\r\nx2 = input('Enter second guess of root location: ');\r\n\r\nitermax = 100;      % max # of iterations\r\niter = 0;\r\nerrmax = 0.001;     % convergence tolerance\r\nerror = 1;\r\nfprintf('\\n   #      x1        x2       x3       rel error\\n\\n');\r\n\r\nwhile error &gt; errmax &amp; iter &lt; itermax\r\n\r\n  iter = iter + 1;\r\n  f1 = fcn(x1);\r\n  f2 = fcn(x2);\r\n\r\n  x3 = x2 - f2*(x2-x1) \/ (f2 - f1);    % here is new root estimate\r\n  plot(x3, fcn(x3),'ro')\r\n\r\n  error = abs((x3 - x2)\/x3) * 100;  % find change from previous\r\n\r\n  fprintf('%3i %8g  %8g  %10.6f   %10.5f\\n',iter,x1,x2,x3,error);\r\n  x1 = x2;      % set up for next iteration\r\n  x2 = x3;\r\nend\r\n\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>% Root finding using Secant method % % The function is defined in another script file as follows: % (Note that this won&#8217;t accept vector inputs) % % function y = fcn(x) % y = x^4 &#8211; 5*x^3 &#8211; 124*x^2 + 380*x + 1200; clear; clf; % First, plot the function to estimate the 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-458","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/458","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=458"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/458\/revisions"}],"predecessor-version":[{"id":459,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/458\/revisions\/459"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}