i have problem in heat equation 1D

3 ビュー (過去 30 日間)
Ali Alaidaros
Ali Alaidaros 2019 年 3 月 9 日
コメント済み: Ali Alaidaros 2019 年 3 月 9 日
%% PROJECT 1
%
%Applications problem in chapter 3 problem 3.1 page 96
%
% $$ Tixt book $$: COMPUTATIONAL FLUID DANAMICS VI
%
% $$ BY $$ K. A. HAFFMANN
%
% $$ Cource \# $$ 804416 & 804441
%
% NAME :ALI MUSTAFA SADEQ ALAIDAROS
% ID # 435025962
clc
clear all
close all
%% Problem definition
%A wall 1 ft. thick and infinite in other directions has
%an initial uniform temperature (??) of 100.0°?. The surface temperature(??)
%at the two sides are suddenly increased and maintained at 300.0°?
%with a diffusivity of ?=0.1 ??2/?? the unsteady
%one-space dimensional heat conduction time intervals from 0.0 to 0.5 hr.
%% Equation:
% The Equation for this problem may be expressed as:
%
% $$\left( {\partial T \over \partial t} = \alpha {\partial^{2} T \over \partial x^{2} } \right) $$
%% Boundary Codition
% $$u(0,t) = 300 F $$
%
% $$u(L,t) = 300 F $$
%% Initial condition
% $$ u(x,0) = 100.0 F $$ for $$0 < x \ L $$
%
% $$u(x,0) = 300 F $$ for $$x = 0$$
% $$u(x,0) = 300 F $$ for $$x = L$$
%% Solution Method: the DuFort-Frankel Explicit Method
% U(n+1,i) = ((1-B).*U(n-1,i) + B .* ( U(n,i+1) + U(n,i-1))./(1+B)
%% Constants declaration
TMAX = 0.5 ; % Maximum time in hour
DT = [0.01 0.005 0.0001] ; % time step
%NM = [((TMAX/DT(1)) + 1) ((TMAX/DT(2)) + 1)]; % # of step in time
alpha = 0.1; % diffusivity constant
L = 1; % the wall lenght
DX = 0.05; % step in x
IM = L/DX + 1; % # of step in x-direction
% B = [(2.*alpha.*DT(1) / (DX.^2)) (2.*alpha.*DT(2) / (DX.^2))]; % The stability requirement
xx = 0:DX:L;
u = zeros(IM) ;
tp = 0:0.1:0.5
%tp =[0.1 0.2 0.3 0.4 0.5]
%% Solution
% Numerical solution
% ------------------------
T(1)=300; %boundry condition
T(IM)=300; %boundry condition
TO(1)=300;
TO(IM)=300;
T((2:IM-1))=100; %initial conditional
TO((2:IM-1))=100;
%%%%%%%%%%%%%
% Solution using DuFort-Forankel Method
for dt=1:2
NM(dt) = ((TMAX/DT(dt)) + 1);
B(dt) = (2.*alpha.*DT(dt) / (DX.^2));
for K=1:NM(dt)
for I=1:IM
TOO(I) = TO(I);
TO(I) = T(I);
TP(I,K) = T(I);
end
for I=2:(IM-1)
T(I)= ( (1 - B(dt))*TOO(I) + B(dt)*( TO(I+1) + TO(I-1) ) ) / ( 1 + B(dt) );
end % myFct: function of the method Dufort-Frankel
end
%% Printing data to file
fprintf('%5s %5s %5s %5s %5s %5s \n',...
'xx','T(I,0.1)','T(I,0.2)',' TP(I,0.3)',' TP(I,0.4)',' TP(I,0.5)');
fprintf('=======================================================================================================\n');
for I=1:IM
TT(I,1) = TP(I,dt*1);
TT(I,2) = TP(I,dt*10);
TT(I,3) = TP(I,dt*20);
TT(I,4) = TP(I,dt*30);
TT(I,5) = TP(I,dt*40);
TT(I,6) = TP(I,dt*50);
fprintf('%6.4f %7.3f %7.3f %7.3f %12.8f %12.8f %12.8f \n',...
xx(I), TT(I,1), TT(I,2), TT(I,3), TT(I,4), TT(I,5), TT(I,6))
end
hold on
for i=1:6
subplot(1,2,dt)
plot(xx,TT(:,i))
xlabel('the wall thickness in foot')
ylabel('T (Fahrenheit)' )
title('TEMPERTURE,DX=0.05,DT=0.01.')
legend('t = 0.0 hour','t = 0.1 hour','t = 0.2 hour','t = 0.3 hour','t = 0.4 hour','t = 0.5 hour')
title('TEMPERTURE,DX=0.05,DT=0.005.')
hold off
hold all
end
end
  3 件のコメント
Geoff Hayes
Geoff Hayes 2019 年 3 月 9 日
編集済み: Geoff Hayes 2019 年 3 月 9 日
Ali - please use comments to add notes to your question (rather than using the tags).
Ali Alaidaros
Ali Alaidaros 2019 年 3 月 9 日
when i run i got two drawing in one plot how to name the x and y axix for each one in same plot

サインインしてコメントする。

回答 (1 件)

Geoff Hayes
Geoff Hayes 2019 年 3 月 9 日
編集済み: Geoff Hayes 2019 年 3 月 9 日
Ali - in the future, please include the error message (if any) that you are observings and be as descriptive as possible...because it is unclear what I get error in legend and y label actually means.
When I run your code, i observe the following warnings
Warning: Ignoring extra legend entries.
> In legend at 290
In *** at 106
Warning: Ignoring extra legend entries.
> In legend at 290
In *** at 106
Warning: Ignoring extra legend entries.
> In legend at 290
In *** at 106
Warning: Ignoring extra legend entries.
> In legend at 290
In *** at 106
Warning: Ignoring extra legend entries.
> In legend at 290
In *** at 106
This is because you are calling legend with all the diffferent labels before you have added all the curves to the subplot. Updating the title, legend, axes labels should occur after you have drawn your curves so that you don't repeat the set of code six times (and avoid the warnings like above). Try simplifying the code to just
subplot(1,2,dt)
plot(xx, TT);
xlabel('the wall thickness in foot')
ylabel('T (Fahrenheit)' )
title('TEMPERTURE,DX=0.05,DT=0.01.')
legend('t = 0.0 hour','t = 0.1 hour','t = 0.2 hour','t = 0.3 hour','t = 0.4 hour','t = 0.5 hour')
title('TEMPERTURE,DX=0.05,DT=0.005.')
Note how there is no loop (which isn't really necessary) and that no warnings appear in the console.
  1 件のコメント
Ali Alaidaros
Ali Alaidaros 2019 年 3 月 9 日
thanks i simplify it ,it's work ,no warrning

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePulse and Transition Metrics についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by