{"id":460,"date":"2017-09-14T12:31:02","date_gmt":"2017-09-14T15:31:02","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=460"},"modified":"2017-09-14T12:31:02","modified_gmt":"2017-09-14T15:31:02","slug":"onepoint-m","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/onepoint-m\/","title":{"rendered":"onepoint.m"},"content":{"rendered":"<pre>% Demonstration of One Point Iteration\r\nclear; figure(1);clf;figure(2);clf;figure(1)\r\n\r\nf = 'exp(-x)-x';       %define the function f(x)=0\r\ng = 'exp(-x)';         %and a    x = g(x)   form\r\n\r\ndisp(['f(x) is ' f]); \r\ndisp(['g(x) is ' g]);\r\n\r\n% plot the function\r\nxmax=3;\r\ngrange = [-xmax xmax];\r\nfigure(1); ezplot(f,grange); hold on; line (grange, [0 0]); pause\r\n\r\n% have a look at the g(x) function\r\nfigure(2); ezplot(g,[-1 xmax]); \r\nhold on\r\nplot([-1 xmax], [-1 xmax],'g')  % line defines x = x\r\n\r\n\r\nx = input ('Enter initial guess of root:        ');\r\nif length(x)==0;x=0;end\r\nmaxerror = 0.1; % maximum error\r\n   maxit = 30;  % maximum number of iterations\r\n   count = 0;   % iteration counter\r\n   error = 1;   % starting error (100 percent)\r\n\r\nfprintf('\\n Iteration      x       g(x)     error(%%)    f(x)\\n\\n');\r\n\r\n\r\n% this is where all the work gets done.....\r\nwhile (error &gt; maxerror) &amp; (count &lt; maxit)\r\n  count = count + 1;\r\n  xnew = eval(g);\r\n  error = abs((xnew - x)\/xnew) * 100;\r\n  fprintf('%7g %10.4f %10.4f %10.4f  %10.4f\\n',count,x,xnew,error,eval(f));\r\n  \r\n  %these 2 lines are added just to show the convergence graphically\r\n  if count&gt;1;line([x x],[x xnew]);else;plot(x,eval(g),'r*');end\r\n  line([x xnew],[xnew xnew]);pause\r\n  \r\n  x = xnew;\r\nend\r\n\r\nif count&lt;maxit\r\n   fprintf('\\nRoot is %g   Function at root is %g\\n',x,eval(f))\r\n   figure(1);plot(x,eval(f),'ro')\r\n   figure(2);plot(x,eval(g),'ro')       % circle at root found\r\nend\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>% Demonstration of One Point Iteration clear; figure(1);clf;figure(2);clf;figure(1) f = &#8216;exp(-x)-x&#8217;; %define the function f(x)=0 g = &#8216;exp(-x)&#8217;; %and a x = g(x) form disp([&#8216;f(x) is &#8216; f]); disp([&#8216;g(x) is &#8216; g]); % plot the function xmax=3; grange = [-xmax xmax]; figure(1); ezplot(f,grange); hold on; line (grange, [0 0]); pause % have a look at [&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-460","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/460","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=460"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/460\/revisions"}],"predecessor-version":[{"id":461,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/460\/revisions\/461"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}