L = 1; %Length of the model
dt = 1e-4; %Length of Timesteps
nt = t/dt; %Timesteps
dx = L / (n-1); %calculated steps
x = 0:dx:1; %range
%x = linspace(0,1,n); %Array of depth von 0 bis 1 mit n
%Gitterpunkten - Gedankengang
%t = linspace(0,t,dt); %timesteps
T = ones(n,nt); %Matrix
%% Initial temperature - Boundary T = (0)
T(:,1) = 0:dx:1; % T = 0 ; x = 0
T(n,:) = 1; % T = 1 ; x = 1
%% Method
time = 0; %Anzeigen lassen der Zeit
for j = 1:nt + 1; %Time Loop
time = time + dt; %Anzeigen lassen der Zeit
for i = 2:n - 1; %Space Loop
T(i,j+1) = T(i,j) + (dt / dx^2)*(T(i+1,j) - 2 * T(i,j) + T(i-1,j)) + Q * dt;
end end
Q = 2; %Heat Source
Q2 = 1; %Heat Source for value 1
n = 50; %number of Gridpoints
t = 0; %Time set0
t2 = 0.1; %Time set0.1
t3 = 0.5; %Time set0.5
[x1,T1] = getT(Q,n,t); %Function getT (another script) calculates with given Parameter Q n t
[x2,T2] = getT(Q,n,t2);
[x3,T3] = getT(Q,n,t3);
%% Plot of the Calculation for Q = 2 figure(1) subplot(1,2,1);
hold on;
plot(x1,T1(:,end),'r');
plot(x2,T2(:,end),'g');
plot(x3,T3(:,end),'b');
xlabel('Depth');
ylabel('Temperature');
title('Temperature - Depth Plot with Q = 2');
legend('t = 0','t = 0.1','t = 0.5')
%% Plot of the Calculation for Q = 1 [x4,T4] = getT(Q2,n,t); %Function getT calculates with given Parameter Q n t
[x5,T5] = getT(Q2,n,t2);
[x6,T6] = getT(Q2,n,t3);
subplot(1,2,2) hold on
plot(x4,T4(:,end),'r');
plot(x5,T5(:,end),'g');
plot(x6,T6(:,end),'b');
xlabel('Depth') ylabel('Temperature') title('Temperature - Depth Plot with Q = 1') legend('t = 0','t = 0.1','t = 0.5')
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.