Appendix
A
Matlab source codes
Contents
A.1 Main script used . . . 112 A.1.1 1DOF , harmonic analysis with force applied . . . 112 A.1.2 1DOF , harmonic analysis with displacement applied . . . 116 A.2 Box connected by four points with displacement control 116 A.2.1 Box on the shaker . . . 116 A.2.2 Function to minimize . . . 119 A.2.3 Input for the shaker . . . 120
A.1
Main script used
In this chapter the main kinds of scripts used are discussed. It will be shown the script for the simplest system: 1DOF mass/spring/damper because it is easy to understand and at the same time it is easy to extend to a complex model modifying the parameters and the connectivity matrix. Also it is shown the displacement control method for the box attached at four point to the engine.
A.1.1 1DOF , harmonic analysis with force applied
It gives the displacement of the mass zDOF, which is plotted with the displacement
of the corresponding mass from the same model analysed in Ansys, (see Appendix B.1.1). Constant damping ratio, ξ, constant on the structure of 0.02 is used in this model.
A.1. MAIN SCRIPT USED
1 %%%%%%%%% A t t e n t i o n
2 %%%%%Don ’ t use v a r i a b l e as i or j when t h e r e a r e complex number
4 c l c; c l e a r ; 5 format compact
6 %%%%%%%%% Parameter %%%%%%%%%
7 DOF = 1+1; % DOF o f t h e s y s t e m s + 1 t h e frame 8 n = 1 ; % Number o f e l e m e n t
9 z_DOF = 2 −1; % Number o f mass t h a t d i s p l a y d i s p l a c e m e n t − 1 , t h e frame 10 f r e q = 1 0 ; % Frequency [ Hz ] 12 %%%%% Mass [ Kg ] %%%%% 13 m( 1 ) = 0 ; %Mass o f t h e frame 14 m( 2 ) = 1 0 ; 16 %%%%% S t i f f n e s s [N/m] %%%%% 17 k ( 1 ) = 1 0 0 0 0 ; 19 %%%%% Damping r a t i o %%%%% 20 x i = 0 . 0 2 ; 22 %%%%%%%%% System %%%%%%%%% 23 % Mass m a t r i x 24 f o r a = 1 :DOF 25 f o r b = 1 :DOF 26 i f a==b 27 M( a , b )=m( a ) ; 28 e l s e 29 M( a , b ) =0; 30 end 31 end 32 end
34 % n e c e s s a r y i f t h e frame i s c o n s t r a i n e d 35 f o r e = 2 :DOF; 36 f o r f = 2 :DOF; 37 M_buffer ( e −1, f −1) = M( e , f ) ; 38 end 39 end 41 M = M_buffer ; 43 %%%%%% C o n n e c t i v e m a t r i x %%%%%% 44 W = [ 1 2 ] ; % I 46 %%%%%% S t i f f n e s s m a t r i x %%%%%% 47 A = zeros (DOF,DOF) ; 48 K = zeros (DOF,DOF) ; 49 f o r c = 1 : n 50 K_buffer=A; 51 K = zeros (DOF,DOF) ; 52 K(W( c , 1 ) ,W( c , 1 ) )=k ( c ) ; 53 K(W( c , 1 ) ,W( c , 2 ) )=−k ( c ) ; 54 K(W( c , 2 ) ,W( c , 1 ) )=−k ( c ) ; 55 K(W( c , 2 ) ,W( c , 2 ) )=k ( c ) ; 56 A=K+K_buffer ; 57 end
58 % Remove t h e frame row and frame column , 1 s t row and column 59 f o r e = 2 :DOF; 60 f o r f = 2 :DOF 61 P( e −1, f −1) = A( e , f ) ; 62 end 63 end 64 K= P ; 66 %%%%%% E i g e n v a l u e and e i g e n v e c t o r %%%%%% 67 M\K; 68 omega_n = sqrt ( eig (M\K) ) ; 69 [ T, E ] = ( eig ( vpa (M\K) ) ) ;
A.1. MAIN SCRIPT USED 70 frequenze_n = ( omega_n ) / ( 2 ∗ pi ) 71 F = 1 ; 73 %%%%%%%%% Harmonic r e s p o n s e %%%%%%%%% 74 H_omega = [ ] ; 75 FREQ = 1 : 1 : f r e q ; 76 OMEGA = 2∗ pi ∗ [FREQ ] ; 77 f o r n = 1 : length (OMEGA) 78 omega = OMEGA( n ) ;
79 H = (−omega^2∗M+i ∗omega ∗ ( ( 2 ∗ x i ) /omega ) ∗k ( 1 )+k ( 1 ) ) \F ; 80 % \ t h e b e s t a l g o r i t h m o f i n v e r s e m a t r i x
81 H_omega = [ H_omega ;H . ’ ] ; % . ’ o n l y t r a n s p o s e d m a t r i x 82 end
83 mz = ( abs (H_omega ( : , z_DOF) ) ) ; %Modulus 1 s t mass 84 save mz_MATLAB. t x t mz −ASCII ;
86 %%%%%%%%% Load %%%%%%%%% 87 m2_rp = load ( ’M2_RP. t x t ’ ) ; 88 m2_ip = load ( ’M2_IP . t x t ’ ) ; 89 m2 = m2_rp+i ∗m2_ip ; 90 abs_m2 = abs (m2) ; 92 %%%%%%%%% P l o t %%%%%%%%% 93 c l f ; 94 f i g u r e( 1 ) 95 %[ 0 . 2 5 2 . 5 8 . 0 6 . 0 ] INCH 96 s e t( gcf , ’ PaperUnits ’ , ’ i n c h e s ’ ) 97 s e t( gcf , ’ P a p e r P o s i t i o n ’ , [ 0 . 2 5 , 2 . 5 , 8 . 0 , 4 . 0 ] ) ; 98 semilogy (FREQ, ( mz) , ’ r∗− ’ ,FREQ, ( abs_m2) , ’ k− ’ ) 99 t i t l e( ’ Comparison ’ , ’ F o n t S i z e ’ , 1 2 )
100 xlabel( ’ Frequency ␣ [ Hz ] ’ , ’ F o n t S i z e ’ , 1 2 ) 101 ylabel( ’ D i s p l ac e m e n t ␣ [m] ’ , ’ F o n t S i z e ’ , 1 2 ) 102 legend ( ’ Matlab ’ , ’ Ansys ’ , 1 )
103 grid
104 s a v e a s ( 1 , ’DispMvsA_Damp ’ , ’ png ’ )
A.1.2 1DOF , harmonic analysis with displacement applied
In this case, the only difference with the previous section, Appendix A.1.1, it is the part concern the harmonic response as shown below.
1 %%%%%%%%% Harmonic r e s p o n s e %%%%%%%%% 2 x = load ( ’ x . t x t ’ ) ; 3 H_omega = [ ] ; 4 FREQ = 1 : 1 : f r e q ; 5 OMEGA = 2∗ pi ∗ [FREQ ] ; 6 f o r n = 1 : length (OMEGA) 7 omega = OMEGA( n ) ;
8 H = (−omega^2∗M+i ∗omega ∗ ( ( 2 ∗ x i ) /omega ) ∗K+K) 9 \ [ ( i ∗omega ∗ ( ( 2 ∗ x i ) /omega ) ∗k ( 1 )+k ( 1 ) ) ∗x ( n ) ] ; 10 % \ t h e b e s t a l g o r i t h m o f i n v e r s e m a t r i x
11 H_omega = [ H_omega ;H . ’ ] ; % . ’ o n l y t r a n s p o s e d m a t r i x 12 end
13 mz = ( ( H_omega ( : , z_DOF) ) ) ; %Modulus 1 s t mass 14 save mz_Matlab . t x t mz −ASCII
A.2
Box connected by four points with displacement
con-trol
It gives the input for the shaker xS enable to obtain the same displacement of
the target point for the box mounted on it, zB, than the box on the engine, zEB.
The script for the whole system, which gives zEB, and for the box on the shaker
with the input found are not shown because can be easy deduced from the previous section and from data reported in Table 2.3, in Table 2.16 and in Table 2.17.
A.2.1 Box on the shaker
This function returns a displacement zB, used on A.2.2.
1 function [ z_B ] = BoxOnShaker ( x , n )
3 %%%%%%%%% Parameter %%%%%%%%%
4 DOF_CE = 1 ; % DOF o f t h e system e n g i n e c o n s t r a i n
A.2. BOX CONNECTED BY FOUR POINTS WITH DISPLACEMENT CONTROL
5 DOF_CB = 4 ; % DOF o f t h e system box c o n s t r a i n 6 DOF_B = 1 3 ; % DOF o f t h e box , ’ number o f mass ’ 7 DOF_EB = 2 4 ; % DOF o f t h e system e n g i n e+box ,
’ number o f mass ’
8 ns = 1 2 ; % Number o f s p r i n g e l e m e n t s 9 f r e q = 2 e2 ; % Frequency [ Hz ]
10 x_DOF = 9−DOF_CB; % Number o f mass t h a t d i s p l a y d i s p l a c e m e n t
11 z_DOF = 13−DOF_CB; % Number o f mass t h a t d i s p l a y d i s p l a c e m e n t 13 %%%%% Mass [ Kg ] %%%%% 14 m( 1 ) = 0 ; m( 2 ) = 0 ; m ( 3 ) = 0 ; m( 4 ) = 0 ; m( 5 ) = 2 ; m( 6 ) = 1 ; 15 m( 7 ) = 2 ; m( 8 ) = 1 ; m( 9 ) = 0 . 5 ; m( 1 0 ) = 0 . 2 ; m( 1 1 ) = 0 . 3 ; 16 m( 1 2 ) = 0 . 4 ; m( 1 3 ) = 0 . 1 ; 18 %%%%% S t i f f n e s s [N/m] %%%%% 19 k ( 1 ) = 3 e7 ; k ( 2 ) = 3 e7 ; k ( 3 ) = 3 e7 ; k ( 4 ) = 3 e7 ; k ( 5 ) = 5 e6 ; 20 k ( 6 ) = 4 e6 ; k ( 7 ) = 3 e6 ; k ( 8 ) = 2 e6 ; k ( 9 ) = 2 e5 ; k ( 1 0 ) = 3 e5 ; 21 k ( 1 1 ) = 1 e5 ; k ( 1 2 ) = 7 e4 ; 23 %%%%% Damping r a t i o %%%%% 24 x i ( 1 ) = 0 . 0 0 5 ; x i ( 2 ) = 0 . 0 1 ; x i ( 3 ) = 0 . 0 2 ; x i ( 4 ) = 0 . 0 5 ; 26 %%%%%%%%% System %%%%%%%%% 27 % Mass m a t r i x 28 f o r a = 1 :DOF_B 29 f o r b = 1 :DOF_B 30 i f a==b 31 M( a , b )=m( a ) ; 32 e l s e 33 M( a , b ) =0; 34 end 35 end 36 end
38 % Remove t h e frame rows and frame columns 39 f o r e = DOF_CB+1:DOF_B;
40 f o r f = DOF_CB+1:DOF_B;
41 M_buffer ( e−DOF_CB, f−DOF_CB) = M( e , f ) ;
42 end 43 end 44 M = M_buffer ; 46 %%%%%% C o n n e c t i v e m a t r i x %%%%%% 47 W = [ 1 5 % I 48 2 6 % I I 49 3 7 % I I I 50 4 8 % IV 51 5 9 % V 52 6 9 % VI 53 7 10 % VII 54 8 10 % VI II 55 9 11 % IX 56 9 12 % X 57 10 12 % XI 58 12 1 3 ] ; % XII 60 %%%%%% S t i f f n e s s m a t r i x %%%%%% 61 A = zeros (DOF_B,DOF_B) ; 62 K = zeros (DOF_B,DOF_B) ; 63 f o r c = 1 : ns 64 K_buffer=A; 65 K = zeros (DOF_B,DOF_B) ; 66 K(W( c , 1 ) ,W( c , 1 ) )=k ( c ) ; 67 K(W( c , 1 ) ,W( c , 2 ) )=−k ( c ) ; 68 K(W( c , 2 ) ,W( c , 1 ) )=−k ( c ) ; 69 K(W( c , 2 ) ,W( c , 2 ) )=k ( c ) ; 70 A=K+K_buffer ; 71 end
72 % Remove t h e frame rows and frame columns 73 f o r e = DOF_CB+1:DOF_B;
A.2. BOX CONNECTED BY FOUR POINTS WITH DISPLACEMENT CONTROL 74 f o r f = DOF_CB+1:DOF_B; 75 P( e−DOF_CB, f−DOF_CB) = A( e , f ) ; 76 end 77 end 78 K= P ; 80 %%%%%%%%% Harmonic r e s p o n s e %%%%%%%%% 81 d = 3 ; %Damping used% 82 H_omega = [ ] ; 83 FREQ = 1 : 0 . 5 : f r e q ; 84 OMEGA = 2∗ pi ∗ [FREQ ] ; 86 %%%%%%%%% Load %%%%%%%%% 87 omega = OMEGA( n ) ;
88 H = (−omega^2∗M+i ∗omega ∗ ( ( 2 ∗ x i ( d ) ) /omega ) ∗K+K) \ 89 [ ( i ∗omega ∗ ( ( 2 ∗ x i ) /omega ) ∗k ( 1 )+k ( 1 ) ) ∗x ;
90 ( i ∗omega ∗ ( ( 2 ∗ x i ) /omega ) ∗k ( 2 )+k ( 2 ) ) ∗x ; 91 ( i ∗omega ∗ ( ( 2 ∗ x i ) /omega ) ∗k ( 3 )+k ( 3 ) ) ∗x ;
92 ( i ∗omega ∗ ( ( 2 ∗ x i ) /omega ) ∗k ( 4 )+k ( 4 ) ) ∗x ; 0 ; 0 ; 0 ; 0 ; 0 ] ; 93 H_omega = [ H_omega ;H . ’ ] ;
94 z_B = abs (H_omega ( : , z_DOF) ) ;
A.2.2 Function to minimize
This function returns the differen between zEB and zB, used on A.2.3.
1 function [ fun ] = d i f f e r ( x , n )
3 %Damping used% 4 y = 3 ;
6 %l o a d%
7 mz_EB = load ( [ ’mz_EB_xi_ ’ num2str ( y ) ’ . dat ’ ] ) ; 8 MZ_eb ( : , y ) = mz_EB;
10 %%%%%%%%% O p t i m i z a t i o n %%%%%%%%% 11 fun = mz_EB( n ) − BoxOnShaker ( x , n ) ;
A.2.3 Input for the shaker
It gives the input for the shaker xS.
1 c l e a r; c l c ; 2 f r e q = 2 e2 ; 3 FREQ = 1 : 0 . 5 : f r e q ; 4 global x n 5 x_S = [ ] ; 6 r e s = [ ] ; 7 x_S_opt = 0 ; 9 %%%%%%%%% Find i n p u t f o r t h e s h a k e r %%%%%%%%% 10 f o r n=1: length (FREQ) 11 x0 = x_S_opt ; 12 [ x_S_opt , f v a l , n ] = fzero ( @ d i f f e r , x0 , x , n ) ; 13 x_S = [ x_S ; x_S_opt ’ ] ; 14 r e s = [ r e s ; f v a l ’ ] ; 15 end
16 save x_S . dat x_S −ASCII