📄 finitedf.mht
字号:
From: <Saved by Windows Internet Explorer 7>
Subject:
Date: Tue, 12 May 2009 09:56:01 -0700
MIME-Version: 1.0
Content-Type: text/html;
charset="Windows-1252"
Content-Transfer-Encoding: 7bit
Content-Location: http://www.mece.ualberta.ca/Courses/mec390/390code/finitedf.m
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.6000.16825" name=GENERATOR></HEAD>
<BODY><PRE>%
% Finite Difference method example of solving boundary value ODE
%
% d^2 T
% ----- + c (Tinf - 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 = 20; % ambient temperature
c = 0.01; % constant
L = 10; % length of bar
ndivs = input('Input number of divisions: ');
nunknowns = ndivs - 1;
deltax = L/ndivs;
A = -(2 + deltax^2*c);
B = -deltax^2*c*Tinf;
matrix = zeros(nunknowns); % initialize
matrix(1,1) = A; % first row
matrix(1,2) = 1;
rhs(1) = B - Ta;
for i = 2:nunknowns - 1 % intermediate rows
matrix(i,i-1) = 1;
matrix(i,i) = A;
matrix(i,i+1) = 1;
rhs(i) = B;
end;
matrix(nunknowns, nunknowns-1) = 1; % last row
matrix(nunknowns, nunknowns) = A;
rhs(nunknowns) = B - Tb;
T = matrix\rhs'; % solve for unknowns
Tfull(1) = Ta; % reconstruct full vector
Tfull(2:1 + nunknowns) = T(:);
Tfull(nunknowns + 2) = Tb;
position = 0:deltax:L;
plot(position,Tfull);
% Tfull' =
% 40.0000
% 65.9698
% 93.7785
% 124.5382
% 159.4795
% 200.0000
</PRE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -