{"id":510,"date":"2017-09-14T13:15:24","date_gmt":"2017-09-14T16:15:24","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=510"},"modified":"2017-09-14T13:15:24","modified_gmt":"2017-09-14T16:15:24","slug":"simpson-m","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/simpson-m\/","title":{"rendered":"simpson.m"},"content":{"rendered":"<pre>%\r\n% Use Matlab's symbolic features to derive Simpson's 1\/3 rule\r\n%\r\n\r\n% define matrix and vector...\r\n%\r\n%   assume data pairs of: (0, y1), (h, y2), (2h, y3)\r\n%\r\n%   fit to: f(x) = a_0 + a_1*x + a_2*x^2\r\n%\r\n\r\nA = sym('[1, 0, 0; 1, h, h^2; 1, 2*h, 4*h^2]')\r\nb = sym('[y1; y2; y3]')\r\n\r\n% solve system of equations\r\n\r\na = linsolve(A,b)\r\n\r\n% form a_0 + a_1*x + a_2*x^2\r\n\r\nf = symadd(symadd(sym(a,1,1),symmul(sym(a,2,1),'x')),symmul(sym(a,3,1),'x^2'))\r\n\r\n% perform integration\r\n\r\ni = int(f,0,'2*h')\r\n\r\n% results\r\n%\r\n% A =  [ 1,   0,     0]\r\n%      [ 1,   h,   h^2]\r\n%      [ 1, 2*h, 4*h^2]\r\n%\r\n% b =  [ y1]\r\n%      [ y2]\r\n%      [ y3]\r\n%\r\n% a =  [                   y1]\r\n%      [-1\/2*(3*y1+y3-4*y2)\/h]\r\n%      [ 1\/2*(y1+y3-2*y2)\/h^2]\r\n%\r\n% f =  y1-1\/2*(3*y1+y3-4*y2)\/h*x+1\/2*(y1+y3-2*y2)\/h^2*x^2\r\n%\r\n% i =  1\/3*h*(y1+4*y2+y3)   as we expect!\r\n%\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>% % Use Matlab&#8217;s symbolic features to derive Simpson&#8217;s 1\/3 rule % % define matrix and vector&#8230; % % assume data pairs of: (0, y1), (h, y2), (2h, y3) % % fit to: f(x) = a_0 + a_1*x + a_2*x^2 % A = sym(&#8216;[1, 0, 0; 1, h, h^2; 1, 2*h, 4*h^2]&#8217;) b = sym(&#8216;[y1; [&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-510","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/510","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=510"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/510\/revisions"}],"predecessor-version":[{"id":511,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/510\/revisions\/511"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}