-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathp28.py
81 lines (81 loc) · 1.61 KB
/
p28.py
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
# HW 05 : Problem 02
import numpy as np
import matplotlib.pyplot as plt
# Parameters
D = 0.49
dt = 6
dx = 2
lamb = ((D * dt) / dx**2)
a = - lamb
b = (1 + 2 * lamb)
c = - lamb
L = 10
l = np.arange(0, (L+dx), dx) # Length
# Boundary Condition
T = [100, 0, 0, 0, 0, 50] # Temperature
# Matrix
matrix = []
m = np.zeros(36).reshape(6, 6)
for i in range(6):
for j in range(6):
if (i+1) == j:
m[i][j] = c
elif (i-1) == j:
m[i][j] = a
elif i == j:
m[i][j] = b
m[0][0] = 1
m[0][1] = 0
m[5][5] = 1
m[5][4] = 0
# After 6 seconds
for x in range(1):
t = (np.linalg.solve(m, T))
T = t
T[0] = 100
T[5] = 50
T6 = t
print(T6)
plt.plot(l, T6, marker='o')
# After 12 seconds
for x in range(2):
t = (np.linalg.solve(m, T))
T = t
T[0] = 100
T[5] = 50
T12 = t
print(T12)
plt.plot(l, T12, marker='x')
# After 18 seconds
for x in range(3):
t = (np.linalg.solve(m, T))
T = t
T[0] = 100
T[5] = 50
T18 = t
print(T18)
plt.plot(l, T18, marker='v')
# After 24 seconds
for x in range(4):
t = (np.linalg.solve(m, T))
T = t
T[0] = 100
T[5] = 50
T24 = t
print(T24)
plt.plot(l, T24, marker='^')
# After 30 seconds
for x in range(5):
t = (np.linalg.solve(m, T))
T = t
T[0] = 100
T[5] = 50
T30 = t
print(T30)
plt.plot(l, T30, marker='<')
# Plotting
plt.xlabel('Distance (m)') # Labeling of X-Axis
plt.ylabel('Temperature degC') # Labeling of Y-axis
plt.title('Distance vs Temperature')
plt.legend(['t = 6', 't = 12', 't = 18', 't = 24', 't = 30'])
plt.show()