forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heat.m
126 lines (100 loc) · 2.56 KB
/
heat.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
function heat(bc,L,c,n,dt,figno)
if nargin < 1, bc = 'f'; end
if nargin < 2, L = pi; end
if nargin < 3, c = 1; end
if nargin < 4, n = 256; end
if nargin < 5, dt = .005; end
if nargin < 6, figno = 1; end
global buttonid;
buttonid=0;
icons = ['text(.5,.5,''pause'' ,''Horiz'',''center'')'
'text(.5,.5,''show time'' ,''Horiz'',''center'')'
'text(.5,.5,''restart'' ,''Horiz'',''center'')'
'text(.5,.5,''init. data'',''Horiz'',''center'')'
'text(.5,.5,''input'' ,''Horiz'',''center'')'
'text(.5,.5,''stop'' ,''Horiz'',''center'')'];
callbacks = ['button(1)'
'button(2)'
'button(3)'
'button(4)'
'button(5)'
'button(6)'];
presstype = ['toggle'
'flash '
'flash '
'flash '
'flash '
'flash '];
hf = figure(figno);
bg = btngroup(hf,'GroupID','b','ButtonId',['p';'s';'r';'0';'d';'i'],...
'IconFunctions',icons,'GroupSize',[1 6],...
'CallBack',callbacks,'Position',[.1 0 .8 .07],...
'PressType',presstype);
h = L/n;
l = dt*c^2/h^2; l2 = l/2;
B = (1 - l) * diag(ones(n+1,1)) + l2 *( diag(ones(n,1),1) + diag(ones(n,1),-1));
A = (1 + l) * diag(ones(n+1,1)) - l2 *( diag(ones(n,1),1) + diag(ones(n,1),-1));
switch bc
case 'p'
B(1,n+1) = l; B(n+1,1) = l;
A(1,n+1) = -l; A(n+1,1) = -l;
case 'n'
B(1,n+1) = l2; B(n+1,1) = l2;
A(1,n+1) = -l2; A(n+1,1) = -l2;
end
C = A\B;
x = linspace(0,L,n+1)';
x0 = 1;
f0 = 0*x;
del = f0; del(25) = 1;
f1 = exp(-40*(x-x0).^2);
f2 = (x < 1) .*x + (x>1 & x < 2.8) .* (3 - 2*x) + (x > 2.8) .* (x - pi) * 2.6 / (pi - 2.8);
f3 = 1 - abs(2*x/L - 1) + .1 * sin(50*x);
f = f1;
clf;
ax = axes('Position',[.15 .17 .75 .75]);
A = 2;
t=0;
sol= plot(x,f,'EraseMode','background');
axis([0 L -A A]);
pause
w = f;
stopit = 0;
while stopit == 0
switch buttonid
case 1
title(['Time: ',num2str(t)]);
buttonid = 0;
while buttonid == 0, pause(.2); end
buttonid = 0;
case 2
title(['Time: ',num2str(t)]);
buttonid = 0;
case 3
clf;
sol= plot(x,f,'EraseMode','background');
axis([0 L -A A]);
w = f;
buttonid = 0;
case 4
title(['Time: ',num2str(t)]);
f = input('Initial temperature: ');
clf;
sol= plot(x,f,'EraseMode','background');
axis([0 L -A A]);
pause
w = f;
buttonid = 0;
case 5
title(['Time: ',num2str(t)]);
keyboard
buttonid = 0;
case 6
stopit = 1;
title(['Time: ',num2str(t)]);
buttonid = 0;
end
w = C * w;
set(sol,'ydata',w); drawnow;
t=t+dt;
end