Download presentation
Presentation is loading. Please wait.
Published byJeffery Bailey Modified over 8 years ago
1
전자장 1 실험 - Matlab 사용법 - Photonic Systems Laboratory School of EE, Seoul National University Photonic Systems Lab School of EECS, S.N.U.
2
Photonic Systems Lab School of EECS, S.N.U. 1. Introduction MATLAB (MATrix LABoratory) 1. Use Matrix/Vector as a basic file Don’t need to do dimensioning 2. Visualization of result by Numerical Analysis & Calculation
3
Photonic Systems Lab School of EECS, S.N.U. 2. Matlab Window ③ Workspace ② Command History ① Command Window (1) Command Window - Do simple calculation or command directly - Check the result - Execute m file (2) Command History - Remain all commands which you use. - All commands which you used are reusable. (3) Workspace - Display occupied information like EXCEL’s spread sheet structure. - User can change data easily.
4
Photonic Systems Lab School of EECS, S.N.U. 3. Simple Examples (1) Built in constant & function - i, j, pi, e, eps - sin, cos, bessel, log, exp (2) Variable list - Enter who - Check it on work space (3) Remove variable - Enter clear (4) Need help - Enter help >> A=1+2i A = 1.0000 + 2.0000i >> B=1-2j B = 1.0000 - 2.0000i >> C=A*B*cos(pi) C = -5 >> who Your variables are: A B C >> clear B >> who Your variables are: A C >> help cos COS Cosine of argument in radians. COS(X) is the cosine of the elements of X. See also acos, cosd. Overloaded methods: darray/cos sym/cos Reference page in Help browser doc cos
5
Photonic Systems Lab School of EECS, S.N.U. 4. Creating Vectors Tip 1. [ 중괄호 ] 로 벡터, Matrix 구분 Tip 2. 공백이나 쉼표로 원소 구분 Tip 3. 콜론 (:) 을 사용하여 수열 형태의 벡터 생성 Tip 4. A(3) : A 벡터의 3 번째 원소 선택 Tip 5. 작은 따옴표 (‘) 를 이용하여 Transpose Tip 6. 세미콜론 (;) 을 사용하여 행 구분 Tip 1. [ 중괄호 ] 로 벡터, Matrix 구분 Tip 2. 공백이나 쉼표로 원소 구분 Tip 3. 콜론 (:) 을 사용하여 수열 형태의 벡터 생성 Tip 4. A(3) : A 벡터의 3 번째 원소 선택 Tip 5. 작은 따옴표 (‘) 를 이용하여 Transpose Tip 6. 세미콜론 (;) 을 사용하여 행 구분 (1) Make Row-vector >> x = [2 2*pi sqrt(2) 2-3j log(2)] x = 2 6.28318 1.414 2-3i 0.6931 (2) Increasing Row-vector >> y = 1:2:9 1 to 9 with increment 2 y = 1 3 5 7 9 (3) Auto Increasing Row-vector >> z = 1:5 1 to 5 with increment 1 z = 1 2 3 4 5 (4) Sum of Vector component >> w = y(1)+z(5) w = 6 (5) Make Column-vector >> v= [1;2;3] v = 1 2 3 (6) Transpose >> t= y’ t = 1 3 5 7 9
6
Photonic Systems Lab School of EECS, S.N.U. 5. Creating & Editing Matrices (1) Method 1 >> X = [1 2 3 4;8 4 0 -4] X = 1 2 3 4 8 4 0 -4 (2) Method 2 >> Y = [1:4; 8:-4:-4] Y = 1 2 3 4 8 4 0 -4 Tip1. Vector 생성시 사용한 방법을 그대로 사용 가능 Tip2. 특정 행에 대한 접근 : X( 행,:) 특정 열에 대한 접근 : X(:, 열 ) Tip1. Vector 생성시 사용한 방법을 그대로 사용 가능 Tip2. 특정 행에 대한 접근 : X( 행,:) 특정 열에 대한 접근 : X(:, 열 ) ♡ For X=[1 2 3;4 5 6], Y=[1 3 5] (1) Insert >> X(1,3)=0 >> X(2,:)=9 >> X(:,3)=8 >> Z=[X;Y] X = X = X = Z = 1 2 0 1 2 0 1 2 8 1 2 8 4 5 6 9 9 9 9 9 8 9 9 8 1 3 5 (2) Extract >> W=X(:,1) >> V=X(:,3:-1:1) W = V = 1 8 2 1 9 8 9 9 Creating matrices Editing matrices
7
Photonic Systems Lab School of EECS, S.N.U. 6. Matrix Operations Tip1. 동일한 dimension 의 matrix 에 대해 동일한 index 의 element 간의 연산 Tip2. scalar(1x1 matrix) 의 경우 dimension 에 관계없이 연산 가능 Tip1. 동일한 dimension 의 matrix 에 대해 동일한 index 의 element 간의 연산 Tip2. scalar(1x1 matrix) 의 경우 dimension 에 관계없이 연산 가능 Tip1. 동일한 dimension 의 matrix 에 대해 동일한 index 의 element 간의 곱셈 :.* Tip2. 일반적인 행렬의 곱셈 : * Tip3. 동일한 dimension 의 matrix 에 대해 동일한 index 의 element 간의 나눗셈 :./ Tip4. 명령 마지막에 세미콜론 (;) 을 붙이면 실행 결과 출력을 생략할 수 있다 Tip1. 동일한 dimension 의 matrix 에 대해 동일한 index 의 element 간의 곱셈 :.* Tip2. 일반적인 행렬의 곱셈 : * Tip3. 동일한 dimension 의 matrix 에 대해 동일한 index 의 element 간의 나눗셈 :./ Tip4. 명령 마지막에 세미콜론 (;) 을 붙이면 실행 결과 출력을 생략할 수 있다 ♡ For X=[1 2 3;4 5 6] (1) Addition(+) & Subtraction(-) >> Y=X-1 >> Z=X-Y >>Y+2 Y = Z = ans = 0 1 2 1 1 1 2 3 4 3 4 5 1 1 1 5 6 7 (2) Multiplication(*.*) & Division(./) >> X.*Y >>W=[1 0;0 1;1 1]; >>X./Y ans = >>V=X*W ans = 0 2 6 V = Inf 2 1.5 12 20 30 4 5 1.33 1.25 1.2 10 11
8
Photonic Systems Lab School of EECS, S.N.U. 7. M File To do complex command at once, it applies MATLAB’s all execute statements. Edit : common text editor, MATLAB Editor/Debugger Execute : MATLAB Editor/Debugger, Command window Like other programming languages, it has similar command construction. ex) for, while, if-else, switch, etc. Script mode m-file - sequential execution for given commands - All variables are remain on workspace
9
Photonic Systems Lab School of EECS, S.N.U. 7. M File
10
Photonic Systems Lab School of EECS, S.N.U. 8. for / while / if ex) Find sin(nπ/10) for integer n(1 to 10) for n=1:10 x(n) = sin(n*pi/10); % make row-vector end for variable = initial : increment : final end for variable = initial : increment : final end while condition end while condition end ex) Find sum of 1 to 10 x=0; sum=0; while x<10 x = x+1; sum = sum+x; end if condition1 elseif condition2 else end if condition1 elseif condition2 else end ex) Distinct sign of n if n > 0 disp('Positive') % print string elseif n < 0 disp('Negative') else disp('Zero') end
11
Photonic Systems Lab School of EECS, S.N.U. 9. Plot Tip. Domain 과 Range 의 length 반드시 일치 ! Creating function Creating graph where Ex1) Draw sin(x), cos(x) graph. Ex2) Draw sinc(x) graph. where
12
Photonic Systems Lab School of EECS, S.N.U. 9. Plot
13
Photonic Systems Lab School of EECS, S.N.U. 10. Report 1. Make sin, cos, sinc function by using for/while structure. And comparing Matlab function and User’s function. Plot them at once for domain. ( 각각의 함수마다 그래프를 그려서 비교하시오. ) 2. Investigating “fft” and making example using “fft” ( 참고 : http://www.matlabinuse.com/?mid=notify&document_srl=852&sort_index=readed_count&order_ty pe=desc) Due 10/14 Friday!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.