{"id":486,"date":"2017-09-14T12:42:26","date_gmt":"2017-09-14T15:42:26","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=486"},"modified":"2017-09-14T12:42:26","modified_gmt":"2017-09-14T15:42:26","slug":"gausseid-m","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/gausseid-m\/","title":{"rendered":"gausseid.m"},"content":{"rendered":"<pre>% Illustration of Gauss-Seidel iteration with relaxation\r\n\r\n% The goal is to determine a value of x1 and x2 that simultaneously\r\n% satisfy the following equations...\r\n%\r\n%   f1(x1,x2) = x1^2 + x2^2 + exp(x1) - 7.7183*x1 = 0\r\n%   f2(x1,x2) = x2 + exp(x2) + x1^3 - 10.389      = 0\r\n\r\n% we will take an x1 out of f1(x1,x2) and an x2 out of f2(x1,x2)\r\n% thus we will have\r\n%\r\n%   x1 = g1(x1,x2) = (x1^2 + x2^2 + exp(x1))\/7.7183 and\r\n%   x2 = g2(x1,x2) = 10.389 - exp(x2) - x1^3\r\n\r\n% in file 'g1.m', we would have:\r\n%\r\n%   function y = g1(x1,x2)\r\n%   y = (x1^2 + x2^2 + exp(x1))\/7.7183;\r\n\r\n% in file 'g2.m', we would have\r\n%\r\n%   function y = g2(x1,x2)\r\n%   y = 10.389 - exp(x2) - x1^3;\r\n\r\n\r\nfprintf('\\nSolution of Non-Linear Equations using Gauss-Seidel iteration\\n');\r\n\r\n      x1 = input('Enter x1 estimate:                   ');\r\n      x2 = input('Enter x2 extimate:                   ');\r\n       w = input('Enter relaxation factor:             ');\r\nmaxerror = input('Enter max relative error (percent):  ');\r\n   maxit = input('Enter max # of iterations:           ');\r\n\r\n  count = 0;\r\n  error = 1;\r\n\r\n  fprintf('\\niteration      x1           x2      error\\n');\r\n  while (error &gt; maxerror) &amp; (count &lt; maxit)\r\n    count = count + 1;\r\n\r\n    x1new = g1(x1,x2);\r\n    error1 = abs((x1new - x1)\/x1new*100); % determine error\r\n    x1 = x1 + w * (x1new - x1);\r\n    \r\n    x2new = g2(x1,x2);\r\n    error2 = abs((x2new - x2)\/x2new*100); % Note: this could all be vectorized!\r\n    x2 = x2 + w * (x2new - x2);\r\n\r\n    error = max(error1,error2);           % find maximum error\r\n  \r\n   fprintf('%6g    %10g %10g %10g\\n',count,x1,x2,error);\r\n\r\n  end<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>% Illustration of Gauss-Seidel iteration with relaxation % The goal is to determine a value of x1 and x2 that simultaneously % satisfy the following equations&#8230; % % f1(x1,x2) = x1^2 + x2^2 + exp(x1) &#8211; 7.7183*x1 = 0 % f2(x1,x2) = x2 + exp(x2) + x1^3 &#8211; 10.389 = 0 % we will take [&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-486","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/486","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=486"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/486\/revisions"}],"predecessor-version":[{"id":487,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/486\/revisions\/487"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}