-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinalProject1a.m
More file actions
73 lines (52 loc) · 1.59 KB
/
FinalProject1a.m
File metadata and controls
73 lines (52 loc) · 1.59 KB
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
%First, we need to initialize our values
tic;
T0 = 20;
M = 200;
TInfinite = 20;
mDot = 0.1;
C = 4180;
hT = 10;
hCoil = 150;
AT = 2;
ACoil = 0.5;
Tin = 70;
%Next, we need to set up the number of times we will loop for h=1
TotalTime = 43200;
h1 = 1;
n = TotalTime/h1+1; %Note that we add 1 here to include the inital condition
T_1 = zeros(n,1);
TimeSteps_1 = linspace(0,TotalTime,n);
T_1(1) = T0;
i = 2;
while i<=n
T_1(i) = T_1(i-1)+h1*(TempChange(mDot,C,M,hCoil,ACoil,hT,AT,TInfinite,Tin,T_1(i-1)));
i = i+1;
end
%Now, we need to repeat for h=300 and h=3600
h2 = 300;
n = TotalTime/h2+1; %Note that we add 1 here to include the inital condition
T_2 = zeros(n,1);
TimeSteps_2 = linspace(0,TotalTime,n);
T_2(1) = T0;
i = 2;
while i<=n
T_2(i) = T_2(i-1)+h2*(TempChange(mDot,C,M,hCoil,ACoil,hT,AT,TInfinite,Tin,T_2(i-1)));
i = i+1;
end
h3 = 3600;
n = TotalTime/h3+1; %Note that we add 1 here to include the inital condition
T_3 = zeros(n,1);
TimeSteps_3 = linspace(0,TotalTime,n);
T_3(1) = T0;
i = 2;
while i<=n
T_3(i) = T_3(i-1)+h3*(TempChange(mDot,C,M,hCoil,ACoil,hT,AT,TInfinite,Tin,T_3(i-1)));
i = i+1;
end
[TimeSteps_4,T_4] = ode45(@(t,T) TempChange(mDot,C,M,hCoil,ACoil,hT,AT,TInfinite,Tin,T),[0 TotalTime], 20);
plot(TimeSteps_1,T_1,'r',TimeSteps_2,T_2,'g',TimeSteps_3,T_3,'b',TimeSteps_4,T_4,'y');
legend("Time Step = 1s", "Time Step = 300s", "Time Step = 3600s", "ode45")
xlabel("Time (s)")
ylabel("Temperature (℃)")
toc;
TSteady = fsolve(@(T) TempChange(mDot,C,M,hCoil,ACoil,hT,AT,TInfinite,Tin,T), 20)