Download presentation
Presentation is loading. Please wait.
Published byLindsay Lester Modified over 8 years ago
1
NoViC, Dept. of Mechanical Eng. 2016. 03. 17
2
Acoustics Lab., NoViC 1. Download Matlab 2
3
Acoustics Lab., NoViC Activation Key 17925-02416-09128-40758-01531 2. Create “Mathworks” account 3
4
Acoustics Lab., NoViC 3. Installation 4 Matlab default view 1 2 3 4 5 6
5
Acoustics Lab., NoViC 1. Input variables and operations (1/5) 5 >> a = 1 a = 1 >> b = 2 b = 2 Command Window >> a + b ans = 3 >> a - b ans = >> a * b ans = 2 >> a / b ans = 0.5000 4 fundamental arithmetic operations Scalar input (real value) Command Window + : Addition - : Subtraction * : Multiplication / : Division Priority of operation: (*, /) > (+, -) >> a + b / a - b ans = 1 >> (a + b) / (a - b) ans = -3 Command Window Square operation (^) >> a^5 (when a=2) ans = 32 >> a^5+1 ans = 33 >> a^(5+1) ans = 64 Command Window
6
Acoustics Lab., NoViC 1. Input variables and operations (2/5) 6 >> c = a+j*b c = 1.0000 + 2.0000i >> c = a+i*b c = 1.0000 + 2.0000i Command Window Scalar input (complex value) i or j : complex variable Trigonometric functions >>x = 45/180*pi x = 0.7854 >> sin(x) ans = 0.7071 >> cos(x) ans = 0.7071 Command Window Complex operations >> real(c) ans = 1 >> imag(c) ans = 2 >> conj(c) ans = 1.0000 - 2.0000i >> abs(c) ans = 2.2361 >> angle(c) ans = 1.1071 Command Window real(c): real value of c imag(c): image value of c conj(c): complex conjugate of c abs(c): absolute value of c angle(c): phase value of c >> tan(x) ans = 1.0000 >> exp(j*x) ans = 0.7071 + 0.7071i Real Im 1-2i 1 2
7
Acoustics Lab., NoViC 1. Input variables and operations (3/5) 7 >> A=[1 2; 3 4] A = 1 2 3 4 >> B=[3 5; 7 9] B = 3 5 7 9 >> C = [1; 5] Command Window Matrix and vector input Matrix-matrix operation >> A + B ans = 4 7 10 13 >> A - B ans = -2 -3 -4 -5 Command Window >> C = [1 5]' C = 1 5 >> D = [2 3] D = 2 3 >> E = [1:2:9] E = 1 3 5 7 9 ; (semicolon): Changing the row : (colon): Pick out selected row ‘ (inverted comma): Transpose operator >> A * B ans = 17 23 37 51 >> A^3 ans = 37 54 81 118 >> A*C ans = 1 5 >> D*A ans = 11 16 Command Window Matrix-vector/scalar operation >> A*5 ans = 5 10 15 20 >> A/2 ans = 0.5 1.0 1.5 2.0
8
Acoustics Lab., NoViC 1. Input variables and operations (4/5) 8 Command Window Other matrix operations >> transpose(A) ans = 1 3 2 4 >> det(A) ans = -2 >> inv(A) ans = -2.0000 1.0000 1.5000 -0.5000 >> A * inv(A) ans = 1.0000 0.0000 0.0000 1.0000 >> [V,D] = eig(A) V = -0.8246 -0.4160 0.5658 -0.9094 D = -0.3723 0 0 5.3723 Command Window >> size(A) ans = 2 2 >> size(C) ans = 2 1 >> length(A) ans = 2 >> length(C) ans = 2 >> eye(2,2) ans = 1 0 0 1 >> zeros(1,2) ans = 0 0 >> ones(1,2) ans = 1 1 transpose(A) same with ‘ (inverted comma) det(A) Determinant of A matrix inv(A) Inverse matrix of A matrix eig(A) Eigenvalues and vectors V: Eigenvectors D: Eigenvalues size(A) Size of A matrix length(A) length of A matrix eye(m,n) Make the mXn identity matrix zeros(m,n) Make the mXn matrix of zeros ones(m,n) Make the mXn matrix of ones
9
Acoustics Lab., NoViC 1. Input variables and operations (5/5) 9 Command Window Comma for matrix computation >> A*B ans = 17 23 37 51 >> A.*B ans = 3 10 21 36 >> A^2 ans = 7 10 15 22 >> A.^2 ans = 1 4 9 16 Command Window >> x=[0:0.1:pi]; >> y=sin(x); ; (semicolon): hide the input/output variables variables save in the workspace Function and vector General matrix multi. Element by element multi. General matrix multi. Element by element multi. Final value (Upper bound) Initial value (Lower bound) Step size X=[0 0.1 0.2 … 2.9 3.1] (Dimension: 1X32) Y=[0 0.0998..0.1411 0.0416] (Dimension: 1X32)
10
Acoustics Lab., NoViC 2. Plotting the graph (1/1) 10 Setting the variables (input and output values) Plotting the figure >> figure(1) >> plot(x, y, 'r-') >> grid on >> xlabel('x [rad]') >> ylabel('sin(x)') >> title('sin function') Command Window >> x=[0:0.1:pi]; >> y=sin(x); figure(1) numbering the figure Plot(x,y,’r-’) x: x-axis data, y: y-axis data, ‘r-’: red solid line grid on show the grid line on the figure To get the more information of plot, Input the help plot in command window Command Window >> help plot semilogx x-axis is log scale semilogy y-axis is log scale loglog x, y-axes are log scale
11
Acoustics Lab., NoViC M-file making 11 F5 Dragging and select several statement +F9 key Run only in the selected part F9
12
Acoustics Lab., NoViC 3. Iteration structure (1/2) 12 >> sum = 0; >> for n = 1:10 sum = sum + n; end >> sum sum = 55 Command Window Example) sum of 1 to 10 for variable = int : n : final statement end Repeat the statement until the final variable Not convenient to use command window Open the editor Click F5 key save the editor Implement the MATLAB program
13
Acoustics Lab., NoViC 3. Iteration structure (2/2) 13 Example) sum of 1 to 10 while conditional statement statement end Repeat the statement until conditional statement is satisfied C.if loop Example) sum of 1 to 10 if expression1 statement1 elseif expression2 statement2 else statement3 end Implement statement1 if expression1 is satisfied, Implement statement2 if expression1 is unsatisfied and expression2 is unsatisfied, Implement statement3 if expression 1 and 2 are unsatisfied
14
Acoustics Lab., NoViC 14 function xdot = sdof(t,x) xdot = zeros(2,1); xdot(1) = x(2); xdot(2) = -(2/3)*x(1) - (1/3)*x(2); 1. First-order form t0 = 0; tf = 20; x0 = [0 0.25]; [t, x] = ode45('sdof', [t0 tf], x0); plot(t,x(:,1),'linewidth',3); hold on; plot(t,x(:,2),'--r','linewidth',3); title('Example 1.9.2'); xlabel('Time'); ylabel('Displacement (solide) and velocity (dashed)'); grid on; sdof.m Tutorial_ode45.m where
15
Acoustics Lab., NoViC 15 1. Start matlab 2. input this code -> urlwrite('https://raw.githubuserconte nt.com/vibrationtoolbox/vtoolbox/ma ster/vtbud.m','vtbud.m'); 3. then input this code -> vtbud 4. Installation will be started You have to select the path where the function files are
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.