-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbar_impact.m
68 lines (58 loc) · 1.43 KB
/
bar_impact.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
L= 5;
N= 20;
E= 70e9;
A= 1e-4;
rho= 2.7*(1000/(100^3));
damp= 1e2;
% get smallest frequency as good inverse time scale
fundamental_freq=bar_modes(N, L, E, A, rho, 1);
fundamental_period=2*pi/fundamental_freq;
% define loading
Fz=@(t)(0);
qz=@(t,z)(0);
Tfinal = 10*fundamental_period;
InitialCond=[zeros(N,1); zeros(N-1,1); 1.0];
sol=bar_dynamic(InitialCond, Tfinal, N, L, E, A, rho, damp, Fz, qz);
% number of time steps in solution
Nt = size(sol.x,2);
% Find limits for plotting
ylimit = max(max(abs(sol.y(1:N,:))));
% repeat numtimes
numtimes = 0;
% run for 10 seconds
delay = 10.0/Nt;
flnm = 'bar_impact_1.gif';
figure(1);
for n=1:Nt
plot(sol.pos, sol.y(1:N,n), 'o-');
axis normal;
axis([0,L, -1.1*ylimit, 1.1*ylimit]);
xlabel('pos (m)');
ylabel('disp (m)');
frame=getframe(1);
im = frame2im(frame);
[A,map] = rgb2ind(im,256);
if n == 1
imwrite(A,map,flnm,'gif','LoopCount',numtimes,'DelayTime',delay);
else
imwrite(A,map,flnm,'gif','WriteMode','append','DelayTime',delay);
end
end;
close(1);
flnm = 'bar_impact_2.gif';
Scale = 0.1*L/ylimit;
figure(2);
for n=1:Nt
plot(sol.pos + Scale*sol.y(1:N,n), zeros(N,1), 'o-');
axis normal;
axis([0,1.2*L, -L/10.0, L/10.0]);
frame=getframe(2);
im = frame2im(frame);
[A,map] = rgb2ind(im,256);
if n == 1
imwrite(A,map,flnm,'gif','LoopCount',numtimes,'DelayTime',delay);
else
imwrite(A,map,flnm,'gif','WriteMode','append','DelayTime',delay);
end
end;
close(2);