-
Notifications
You must be signed in to change notification settings - Fork 0
/
bar_vibration_modes.m
265 lines (192 loc) · 5.76 KB
/
bar_vibration_modes.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
%% Program: Torsion
%
% @DESCRIPTION: Define the different vibration modes of a free-free or free-clamped bar
% @AUTHOR: Renan Miranda Portela
%
%% Clen memory and close all windows open
clear all
close all
clc
%% COORDINATE MATRIX
% coord = [number | X-position | Y-position]
node = 49; % number of nodes
L = 1; % length
coord = zeros(node-1,3);
for i = 1:node
coord(i,1) = i; % node number
coord(i,2) = L/(node-1)*(i-1); % X-coordinate
coord(i,3) = 0; % Y-coordinate
end
%% INCIDENCE MATRIX
% inci = [number | material | geometry | node-1 | node-2 ]
inci = zeros(node-1,5);
for i = 1:node-1
inci(i,1) = i; % node number
inci(i,2) = 1; % material
inci(i,3) = 1; % geometry
inci(i,4) = i; % node-1
inci(i,5) = i +1; % node-2
end
%% MATERIALS TABLE
% Tmat = [ Material 1 | Material 2 | Material 3 ...]
%
% column 1: Young's modulus
% column 2: Poisson ratio
tabmat = [210E9 0.33];
%% GEOMETRY TABLE
% Tgeo = [ Geometria 1 | Geometria 2 | Geometria 3 ...]
%
% column 1: area - square meter
% column 2: density - kg/m³
tabgeo = [0.1 7860];
%% BOUNDARY CONDITIONS
% bc = [node | degree of freedom (DF) | value]
%
% DF 1 --> x
% DF 2 --> y
% DF 3 --> z
% DF 4 --> ox
% DF 5 --> oy
% DF --> oz
% bc=[]; % Free-Free bar
bc=[1 1 0]; % Clamped-Free bar
%% EXTERNAL LOAD
% F = [node | DF | value]
%
% DF 1 --> Fx
% DF 2 --> Fy
% DF 3 --> Fz
% DF 4 --> Mx
% DF 5 --> My
% DF 6 --> Mz
Load=[];
% VECTOR SIZES
nbc = size(bc,1); % number of boundary conditions
nF = size(Load,1); % number of external loads
neq = 0; % number of equations
ngdl = 1; % number of degrees of freedom
%% Assembly of global mass and stiffness matrices
id=ones(1,node);
for i=1:nbc
id(bc(i,2),bc(i,2))=bc(i,3);
end
for i= 1:node
for j = 1:ngdl
if id(j,i)== 1
neq = neq +1;
id(j,i) = neq;
end
end
end
kg = zeros(neq,neq); % pre-allocation of global stiffness matrix
mg = zeros(neq,neq); % pre-allocation of global mass matrix
for i = 1:node-1 % matrices assembly
no1 = inci(i,4);
no2 = inci(i,5);
x1 = coord(no1,2);
x2 = coord(no2,2);
l = x2 - x1;
mat = inci(i,2);
geo = inci(i,3);
E = tabmat(1,mat);
a = tabgeo(1);
rho = tabgeo(2);
ke = 1/l*[1 -1; -1 1]; % local stiffness matrix
me = 1*l/6*[2 1;1 2]; % local mass matrix
loc = [id(1,no1),id(1,no2)];
for j = 1:2
if loc(j) ~= 0;
for k = 1:2
if loc(k) ~=0
kg(loc(j),loc(k))=kg(loc(j),loc(k))+ke(j,k);
mg(loc(j),loc(k))=mg(loc(j),loc(k))+me(j,k);
end
end
end
end
end
[theta,D]=eig(kg,mg); % theta = vibration mode
for i = 1:size(theta,1)
theta(:,i) = theta(:,i)/max(abs(theta(:,i)));
end
lambda = diag(D); % eigenvalues [K] - lambda*[M] = 0
poisson = tabmat(2);
G = E/(2*(1+poisson));
b = 1;%sqrt(G/rho);
omega = sqrt(lambda)*b; % vibration frequency
coord_2 = coord; %coord_2 = node coordinate after vibration
y_1 = zeros(node,1);
if isempty(bc)
for i = 1 : node-1 % first mode of vibration
coord_2(i+1,3) = coord_2(i+1,3) + theta(i,2);
y_1(i+1) = sin((pi*coord_2(i+1,2))/2);
end
figure(1)
plot(coord_2(:,2),coord_2(:,3),'*-')
title('Modos de vibração')
xlabel('Comprimento da barra sob torção (m)') % x-axis label
ylabel('Deslocamento vertical do nó') % x-axis label
hold on
coord_2 = coord;
if node >= 3
y_2 = zeros(node,1);
for i = 1 : node-1 % second mode of vibration
coord_2(i+1,3) = coord_2(i+1,3) - theta(i,3);
y_2(i+1) = sin((3*pi*coord_2(i+1,2))/2);
end
erro_2 = norm(abs(coord_2(:,3))-abs(y_2));
plot(coord_2(:,2),coord_2(:,3),'k')
coord_2 = coord;
end
if node >= 4
y_3 = zeros(node,1);
for i = 1 : node-1 % third mode of vibration
coord_2(i+1,3) = coord_2(i+1,3) + theta(i,4);
y_3(i+1) = sin((5*pi*coord_2(i+1,2))/2);
end
erro_3 = norm(abs(coord_2(:,3))-abs(y_3));
plot(coord_2(:,2),coord_2(:,3),'r--')
legend('Primeiro','Segundo','Terceiro')
coord_2 = coord;
end
else
for i = 1 : node-1 % first mode of vibration
coord_2(i+1,3) = coord_2(i+1,3) - theta(i,1);
y_1(i+1) = sin((pi*coord_2(i+1,2))/2);
end
erro = norm(abs(coord_2(:,3))-abs(y_1));
figure(1)
plot(coord_2(:,2),coord_2(:,3),'*-')
title('VIbration modes')
xlabel('Bar length under torsion (m)') % x-axis label
ylabel('Vertical node displacement (m)') % y-axis label
hold on
coord_2 = coord;
if node >= 3
y_2 = zeros(node,1);
for i = 1 : node-1 % second vibration mode
coord_2(i+1,3) = coord_2(i+1,3) + theta(i,2);
y_2(i+1) = sin((3*pi*coord_2(i+1,2))/2);
end
erro_2 = norm(abs(coord_2(:,3))-abs(y_2));
plot(coord_2(:,2),coord_2(:,3),'k')
coord_2 = coord;
end
if node >= 4
y_3 = zeros(node,1);
for i = 1 : node-1 % third vibration mode
coord_2(i+1,3) = coord_2(i+1,3) - theta(i,3);
y_3(i+1) = sin((5*pi*coord_2(i+1,2))/2);
end
erro_3 = norm(abs(coord_2(:,3))-abs(y_3));
plot(coord_2(:,2),coord_2(:,3),'r--')
legend('Primeiro','Segundo','Terceiro')
coord_2 = coord;
end
end
fprintf('\n\n******* Eigenvalues *******\n')
fprintf(' %f\n',lambda)
fprintf('\n\n******* Vibration frequencies *******\n')
fprintf(' %f\n',omega)
fprintf('\n\n******* First vibration mode *******\n')
fprintf(' %f\n',theta(:,1))