{"id":559,"date":"2017-09-14T13:37:24","date_gmt":"2017-09-14T16:37:24","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=559"},"modified":"2017-09-14T13:37:24","modified_gmt":"2017-09-14T16:37:24","slug":"finitedf-m","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/finitedf-m\/","title":{"rendered":"finitedf.m"},"content":{"rendered":"<pre>%\r\n% Finite Difference method example of solving boundary value ODE\r\n%\r\n%     d^2 T   \r\n%     -----  + c (Tinf - T) = 0\r\n%      dx^2\r\n%\r\n% which models the temperature distribution in a rod\r\n\r\n% define constants\r\n\r\nTa   = 40;      % left side temperature\r\nTb   = 200;     % right side temperature\r\nTinf = 20;      % ambient temperature\r\nc    = 0.01;    % constant\r\n\r\nL      = 10;    % length of bar\r\n\r\nndivs  = input('Input number of divisions: ');\r\nnunknowns = ndivs - 1;\r\ndeltax = L\/ndivs;\r\n\r\nA = -(2 + deltax^2*c);\r\nB = -deltax^2*c*Tinf;\r\n\r\nmatrix = zeros(nunknowns);  % initialize\r\n\r\nmatrix(1,1) = A;                          % first row\r\nmatrix(1,2) = 1;\r\nrhs(1)      = B - Ta;\r\n\r\nfor i = 2:nunknowns - 1                   % intermediate rows\r\n  matrix(i,i-1) = 1;\r\n  matrix(i,i)   = A;\r\n  matrix(i,i+1) = 1;\r\n  rhs(i)        = B;\r\nend;\r\n\r\nmatrix(nunknowns, nunknowns-1) = 1;       % last row\r\nmatrix(nunknowns, nunknowns)   = A;\r\nrhs(nunknowns)                 = B - Tb;\r\n\r\nT = matrix\\rhs';                          % solve for unknowns\r\n\r\nTfull(1)               = Ta;              % reconstruct full vector\r\nTfull(2:1 + nunknowns) = T(:);\r\nTfull(nunknowns + 2)   = Tb;\r\n\r\nposition = 0:deltax:L;\r\nplot(position,Tfull);\r\n\r\n% Tfull' = \r\n%   40.0000\r\n%   65.9698\r\n%   93.7785\r\n%  124.5382\r\n%  159.4795\r\n%  200.0000\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>% % Finite Difference method example of solving boundary value ODE % % d^2 T % &#8212;&#8211; + c (Tinf &#8211; T) = 0 % dx^2 % % which models the temperature distribution in a rod % define constants Ta = 40; % left side temperature Tb = 200; % right side temperature Tinf = [&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-559","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/559","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=559"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/559\/revisions"}],"predecessor-version":[{"id":560,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/559\/revisions\/560"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}