{"id":484,"date":"2017-09-14T12:42:08","date_gmt":"2017-09-14T15:42:08","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=484"},"modified":"2017-09-14T12:42:08","modified_gmt":"2017-09-14T15:42:08","slug":"gssornl-m","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/gssornl-m\/","title":{"rendered":"gssornl.m"},"content":{"rendered":"<pre>% Illustration of Gauss-Seidel iteration with relaxation\r\n%\r\n% NON-LINEAR SYSTEM\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% The g-functions are defined in files 'g1.m' and 'g2.m'\r\n%\r\n\r\nclear;\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 approx error    : ');\r\n   maxit = input('Enter max # of iterations : ');\r\n\r\ncount = 0;\r\nerror = 1;\r\n\r\nfprintf('\\niteration      x1           x2      max error\\n');\r\n\r\nwhile (error &gt; maxerror) &amp; (count &lt; maxit)\r\n    count = count + 1;\r\n\r\n    temp = g1(x1,x2);\r\n    x1new = x1 + w * (temp - x1);\r\n\r\n    temp = g2(x1new,x2);\r\n    x2new = x2 + w * (temp - x2);\r\n\r\n    error1 = abs(x1new - x1);\r\n    error2 = abs(x2new - x2);\r\n    error = max([error1,error2]);\r\n  \r\n    fprintf('%6g    %10g %10g %10g\\n',count,x1new,x2new,error);\r\n\r\n    x1 = x1new;                           % assign new values\r\n    x2 = x2new;\r\nend\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>% Illustration of Gauss-Seidel iteration with relaxation % % NON-LINEAR SYSTEM % % 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 = [&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-484","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/484","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=484"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/484\/revisions"}],"predecessor-version":[{"id":485,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/484\/revisions\/485"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}