-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeat_Conduction_Homogeneous_1D_V1_0.m
235 lines (231 loc) · 7.33 KB
/
Heat_Conduction_Homogeneous_1D_V1_0.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
clc
clear
close all
%Introduction
disp('Welcome to Homogeneous 1D Heat Conduction Problems ver 2.0');
disp('DISCLAIMER: The program took a long time to run, please do be patient');
disp('This MatLab code are made for Heat Conduction Problems');
disp('The modes in this codes are: Plotting and calculating Homogenous heat conduction,');
disp('With plotting variation on time (max = 3) and N');
disp('Further optimization and range addition could be conducted with more time');
disp('The program made by M.Lucky Witjaksono');
disp('The program will be beneficial for faster system analsys');
disp(' ')
disp('This programs run on the equations of: ');
disp('U(X,T) = X(x)T(t)');
disp('u(x,t) = Cn Un (x,t) = sigma Cn exp^((-(n^2)(phi^2)(a^2)(t))/(L^2)) sin(n phi x/L)');
disp('With Cn of (2/L)Integral[L to 0] f(x) sin(n phi x / L) dx');
%User data input
disp('The following are the input required by the program');
L = input('Rod length (meter): ');
A = input('Thermal diffusivity (alpha^2): ');
step = input('Step along the rod (min 1): ');
if step<=0
disp('Invalid input, Please Re-Run The program');
return
end
n = input('n Value (n>1): ');
%Initial Condition Input
syms x
ICC = input('initial conditon is a polynominal with fuction of X? yes(1),no(0): ');
if ICC ==1
ICCP = input('Power of the equation (max =3): ');
if ICCP == 1
var1 = input('Variable from X^1: ');
varC = input('Variable from X^0: ');
IC = (var1*(x^1))+(varC);
elseif ICCP == 2
var1 = input('variable from X^2: ');
var2 = input('variable from X^1: ');
varC = input('Variable from X^0: ');
IC = (var1*(x^2))+(var2*(x))+(varC);
elseif ICCP == 3
var1 = input('variable from X^3: ');
var2 = input('variable from X^2: ');
var3 = input('variable from X^1: ');
varC = input('Variable from X^0: ');
IC = (var1*(x^3))+(var2*(x^2))+(var3*(x))+(varC);
else
disp('Invalid Input, Please re-run the program')
return
end
elseif ICC ==0
IC = input('Initial Temperature: ');
else
disp('Invalid Input, Please re-run the program');
return
end
%User input summary
disp('The user input are as follows:');
disp('Rod Length: ');
disp(L);
disp('Thermal diffusivity (alpha^2)');
disp(A);
disp('Initial temperature distribution [f(x)]');
disp(IC);
disp('Step along the rod:');
disp(step)
%rod coordinate matrix
rodplot(1,1:((L/step)+1))=0:step:L;
%Time variation based plotting
iet = input('how much t(second) are wanted to be plotted (max = 3)? ');
if iet ==1
%Temperature calculation based on 1 time input
T1 = input('T1 value (Seconds): ');
Matiex = 1;
iex = 0;
while iex <= L
ien = 1;
while ien<=n
FM(ien,Matiex) = ((exp(((-1)*(ien^2)*(pi^2)*(A^2)*(T1))/(L^2)))...
*(sin((ien*pi*iex)/(L)))*...
(integral(matlabFunction((2/L)*IC*sin((ien*pi*x)/(L))),0,L)));
ien = 1+ien;
end
dX(1,Matiex)= iex;
iex = iex+step;
Matiex = 1+Matiex;
end
if n==1
FM_sum = FM;
else
FM_sum = sum(FM);
end
%Graph Plotting
plot(dX,FM_sum,'DisplayName','T1')
xlabel('Rod length');
ylabel('Temperature');
lgd = legend;
legend('show')
title('Temperature Distribution')
elseif iet ==2
%Temperature calculation based on 2 time input
T1 = input('T1 value (Seconds): ');
T2 = input('T2 value (Seconds): ');
%Calculation for T1
Matiex = 1;
iex = 0;
while iex <= L
ien = 1;
while ien<=n
FM1(ien,Matiex) = ((exp(((-1)*(ien^2)*(pi^2)*(A^2)*(T1))/(L^2)))...
*(sin((ien*pi*iex)/(L)))*...
(integral(matlabFunction((2/L)*IC*sin((ien*pi*x)/(L))),0,L)));
ien = 1+ien;
end
dX(1,Matiex)= iex;
iex = iex+step;
Matiex = 1+Matiex;
end
if n==1
FM1_sum = FM1;
else
FM1_sum = sum(FM1);
end
%Calculation for T2
Matiex = 1;
iex = 0;
while iex <= L
ien = 1;
while ien<=n
FM2(ien,Matiex) = ((exp(((-1)*(ien^2)*(pi^2)*(A^2)*(T2))/(L^2)))...
*(sin((ien*pi*iex)/(L)))*...
(integral(matlabFunction((2/L)*IC*sin((ien*pi*x)/(L))),0,L)));
ien = 1+ien;
end
iex = iex+step;
Matiex = 1+Matiex;
end
if n==1
FM2_sum = FM2;
else
FM2_sum = sum(FM2);
end
%Graph Plotting
plot(dX,FM1_sum,'DisplayName','T1')
hold on
plot(dX,FM2_sum,'DisplayName','T2')
hold off
xlabel('Rod length');
ylabel('Temperature');
lgd = legend;
legend('show')
title('Temperature Distribution')
elseif iet ==3
%Temperature calculation based on 2 time input
T1 = input('T1 value (Seconds): ');
T2 = input('T2 value (Seconds): ');
T3 = input('T3 value (Seconds): ');
%Calculation for T1
Matiex = 1;
iex = 0;
while iex <= L
ien = 1;
while ien<=n
FM1(ien,Matiex) = ((exp(((-1)*(ien^2)*(pi^2)*(A^2)*(T1))/(L^2)))...
*(sin((ien*pi*iex)/(L)))*...
(integral(matlabFunction((2/L)*IC*sin((ien*pi*x)/(L))),0,L)));
ien = 1+ien;
end
dX(1,Matiex)= iex;
iex = iex+step;
Matiex = 1+Matiex;
end
if n==1
FM1_sum = FM1;
else
FM1_sum = sum(FM1);
end
%Calculation for T2
Matiex = 1;
iex = 0;
while iex <= L
ien = 1;
while ien<=n
FM2(ien,Matiex) = ((exp(((-1)*(ien^2)*(pi^2)*(A^2)*(T2))/(L^2)))...
*(sin((ien*pi*iex)/(L)))*...
(integral(matlabFunction((2/L)*IC*sin((ien*pi*x)/(L))),0,L)));
ien = 1+ien;
end
iex = iex+step;
Matiex = 1+Matiex;
end
if n==1
FM2_sum = FM2;
else
FM2_sum = sum(FM2);
end
%Calculation for T3
Matiex = 1;
iex = 0;
while iex <= L
ien = 1;
while ien<=n
FM3(ien,Matiex) = ((exp(((-1)*(ien^2)*(pi^2)*(A^2)*(T3))/(L^2)))...
*(sin((ien*pi*iex)/(L)))*...
(integral(matlabFunction((2/L)*IC*sin((ien*pi*x)/(L))),0,L)));
ien = 1+ien;
end
iex = iex+step;
Matiex = 1+Matiex;
end
if n==1
FM3_sum = FM3;
else
FM3_sum = sum(FM3);
end
%Graph Plotting
plot(dX,FM1_sum,'DisplayName','T1')
hold on
plot(dX,FM2_sum,'DisplayName','T2')
plot(dX,FM3_sum,'DisplayName','T3')
hold off
xlabel('Rod length');
ylabel('Temperature');
lgd = legend;
legend('show')
title('Temperature Distribution')
end
disp('Thank you for using the program');
disp('CopyRight - Muhammad Lucky Witjaksono');
disp('Contact: github.com/mluckyw');