-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbar_forced.m
76 lines (66 loc) · 1.7 KB
/
bar_forced.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
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
forcing_freq = 0.8*fundamental_freq;
forcing_period = 2*pi/forcing_freq;
Fz=@(t)((5e4)*cos(forcing_freq*t - pi/2.0));
qz=@(t,z)(0);
Tfinal = 10*forcing_period;
InitialCond=zeros(2*N,1);
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_forced_1.gif';
figure(1);
for n=1:Nt
plot(sol.pos, sol.y(1:N,n), 'o-');
hold on;
quiver(sol.pos(N),sol.y(N,n), 0, 0.3*ylimit*Fz(sol.x(n))/(5e4));
hold off;
axis normal;
axis([0,1.05*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_forced_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-');
hold on;
quiver(sol.pos(N) + Scale*sol.y(N,n), 0, 0.1*L*Fz(sol.x(n))/(5e4), 0);
hold off;
axis normal;
axis([0,1.3*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);