Top Banner
매트랩과 그래프 순천향대학교 정보통신공학과 김상준 2013.3.21
53

매트랩과 그래프

Nov 07, 2014

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 매트랩과 그래프

매트랩과 그래프

순천향대학교 정보통신공학과

김상준 2013.3.21

Page 2: 매트랩과 그래프

내용 구성

• 매트랩과 그래픽

• 신호 및 시스템과 매트랩

Page 3: 매트랩과 그래프

매트랩과 그래픽

Page 4: 매트랩과 그래프

>> f = ‘sin(x)’;

>> fplot (f,[0 4*pi])

>>

명령어 창 : Command Window

Page 5: 매트랩과 그래프

>> grid

>>

함수 그래프 그리기

Page 6: 매트랩과 그래프

>> grid

>>

함수 그래프 그리기

Page 7: 매트랩과 그래프

>> axis([0 4*pi -1.5 1.5])

>>

기능 : 함수 그래프 그리기

Page 8: 매트랩과 그래프

>> x = linspace (0 4*pi);

>> y = sin(x);

>> plot (x, y)

명령어 창 : Command Window

“ 명령어에서

사실은 틀린

부분은 ? “

Page 9: 매트랩과 그래프

명령어 : linspace

linspace( a, b ) linspace( a, b, n )

a 와 b 사이에 같은 간격의 100개 원소를 갖는 행 벡터 생성 a 와 b 사이에 같은 간격의 n 개 원소를 갖는 행 벡터 생성

logspace( a, b ) logspace( a, b, n )

10a와 10b 사이에 로그 스케일의 같은 간격의 50개 원소를 갖는 행 벡터 생성 10a와 10b 사이에 로그 스케일의 같은 간격의 n 개 원소를 갖는 행 벡터 생성

Page 10: 매트랩과 그래프

>> axis ([0 4*pi -1 1]);

>>

명령어 창 : Command Window

Page 11: 매트랩과 그래프

>> t = [0;0.1;4*pi];

>> y1= sin(t/2);

>> y2 = sin(t/4);

>> y3 = cos(t/2);

>> plot(t, y1, t y2, t, y3)

‘ 여러 그래프 그리기 ‘ 한꺼번에 그리기

“ 조건 : y1, y2, y3 세 개 그래프의 x 축 사이즈가 동일해야 한다. “

Page 12: 매트랩과 그래프

>> plot ( t, y1, t , y2, t, y3 )

‘ 여러 그래프 그리기 ‘ 한꺼번에 그리기

Page 13: 매트랩과 그래프

>> t = [0;0.1;4*pi];

>> y1= sin(t/2);

>> y2 = sin(t/4);

>> y3 = cos(t/2);

>> plot(t, y1, t y2, t, y3)

‘ 여러 그래프 그리기 ‘ 한꺼번에 그리기

Page 14: 매트랩과 그래프

>> subplot = (311)

>> plot( t, y1 )

>>

‘ 여러 그래프 그리기 ‘ 나눠 그리기

Page 15: 매트랩과 그래프

>> subplot = (311)

>> plot( t, y1 )

>> subplot = (313)

‘ 여러 그래프 그리기 ‘ 나눠 그리기

Page 16: 매트랩과 그래프

>> subplot = (311)

>> plot( t, y1 )

>> subplot = (313)

>> plot( t, y3 )

‘ 여러 그래프 그리기 ‘ 나눠 그리기

Page 17: 매트랩과 그래프

“subplot” 명령어의 크기와 위치 지정

subplot (211)

subplot (212)

subplot(311)

subplot(312)

subplot(313)

subplot (221) subplot (22?)

subplot (22?) subplot (224)

subplot (?) subplot (322)

subplot (323) subplot (324)

subplot (325) subplot (326)

Page 18: 매트랩과 그래프

>> plot(t, y1)

>> hold on

>>

‘ 그래프 위에 그래프 겹쳐 그리기 ‘ hold on

Page 19: 매트랩과 그래프

>> plot(t, y1)

>> hold on

>> plot(t, y2)

‘ 그래프 위에 그래프 겹쳐 그리기 ‘ hold on

Page 20: 매트랩과 그래프

>> plot(t, y1)

>> hold on

>> plot(t, y2)

>> plot(t, y3)

>> hold off

‘ 그래프 위에 그래프 겹쳐 그리기 ‘ hold on

Page 21: 매트랩과 그래프

>> ezplot (‘sin(t)’)

>>

‘ 편리하게 그래프 그리기 ‘ ezplot

Page 22: 매트랩과 그래프

>> ezplot (‘sin(t)’, [0 4*pi])

>>

‘ 편리하게 그래프 그리기 ‘ ezplot

Page 23: 매트랩과 그래프

>>x = sym(‘x’);

>> ezplot (x - 1/6*x^3 + 1/60*x^5 - 1/5040*x^7);

>> ezplot (x-1/factorial(3)*x^3+1/factorial(5)*x^5-1/factorial(7)*x^7+1/factorial(9)*x^9);

‘ 편리하게 그래프 그리기 ‘ ezplot

Page 24: 매트랩과 그래프

>>x = sym(‘x’);

>> explot( 1+ x + ½*x^2 + 1/3*x^3 + 1/12*x^4);

>> explot( 1+ x + ½ *x^2 + 1/3*x^3 + 1/12*x^4+ 1/60*x^5);

‘ 편리하게 그래프 그리기 ‘ ezplot

Page 25: 매트랩과 그래프

>> plot (t, y1)

>>

‘ 그래프 그리기 plot 명령어‘ 관찰해보자 !

Page 26: 매트랩과 그래프

>> figure(1)

>>

‘ 그래프 창 생성하기 ‘ figure(n)

Page 27: 매트랩과 그래프

>> figure(1)

>> figure(2)

‘ 그래프 창 생성하기 ‘ figure(n)

Page 28: 매트랩과 그래프

>> figure(1)

>> figure(2)

>> ezplot (‘sin(x)’)

‘ 그래프 창 생성하기 ‘ figure(n)

Page 29: 매트랩과 그래프

숙제 3월 21일

1. 함수 f(y) = 3y 를 fplot, plot, ezplot 으로 그리시오.

2. 함수 f(y) = y2 를 fplot, plot, ezplot 으로 그리시오.

3. 함수 f(y) = y(1-y) 를 fplot, plot, ezplot 으로 그리시오.

4. 함수 f(y) = y(y-1)을 fplot, plot, ezplot 으로 그리시오.

5. 함수 f(y) = y2-1을 fplot, plot, ezplot 으로 그리시오.

6. 함수 f(y) = y(y2-1)을 fplot, plot, ezplot 으로 그리시오.

7. 함수 f(y) = y2(y2-1)을 fplot, plot, ezplot 으로 그리시오.

8. plot 을 사용하여 5~7 의 그래프를 하나의 창에 그리시오.

9. subplot 을 사용하여 1~7 의 그래프를 모두 그리시오.

Page 30: 매트랩과 그래프

>> x = [ 2, 1, -1, 0, 1, 4, 3, 7, 4, -3 ];

>> stem (x)

‘ 이산 신호 그리기 ‘ stem(x)

Page 31: 매트랩과 그래프

>> n = [ -3 : 10 ];

>> x = [ 2, 1, -1, 0, 1, 4, 3, 7, 4, -3, 4, 2, -1, 2];

>> stem ( n, x )

‘ 이산 신호 그리기 ‘ stem(n, x)

Page 32: 매트랩과 그래프

>> n = [0:0.1:2];

>> x = exp(n);

>> stem (n , x)

‘ 이산 신호 그리기 ‘ stem(n, x)

Page 33: 매트랩과 그래프

>> t = [ 0; 0.2; 4*pi ];

>> x= sin( t );

>> stem( t, x )

‘ 이산 신호 그리기 ‘ stem(n, x)

Page 34: 매트랩과 그래프

>> t = [0;0.2;4*pi];

>> x= sin( t );

>> plot( t, x, ‘o’)

‘ 점 그래프 그리기 ‘ plot(t, x, ‘o’)

Page 35: 매트랩과 그래프

심볼릭 사용법

Page 36: 매트랩과 그래프

심볼릭 사용법 I.6 MATLAB 심볼릭 툴박스 사용법

변수의 심볼릭 정의

Page 37: 매트랩과 그래프

심볼릭 사용법 I.6 MATLAB 심볼릭 툴박스 사용법

expand 명령어

의 MATLAB 표현

의 전개

Page 38: 매트랩과 그래프

심볼릭 사용법 I.6 MATLAB 심볼릭 툴박스 사용법

factor 명령어 :

simplify 명령어 :

의 MATLAB 표현

인수분해 결과

의 간단한 표현

Page 39: 매트랩과 그래프

심볼릭 사용법 I.6 MATLAB 심볼릭 툴박스 사용법

ezplot 명령어 :

시뮬레이션 결과

Page 40: 매트랩과 그래프

매트랩 기본 사항들 ( 경로 설정, 내장 함수 )

Page 41: 매트랩과 그래프

함 수 설 명 예

sqrt (x) X의 제곱근 >> sqrt (4)

ans = 2

exp (x) 지수 >> exp (1)

ans = 2.7183

abs(x) 절대값 >> abs (-7)

ans = 7

log(x) 자연로그

ln(x)

>> log(100)

ans = 4.6052

log10(x) 상용로그 >> log10(100)

ans = 2.0000

factorial(x) x! >> factorial (4)

ans = 24

매트랩 내장 수학 함수

Page 42: 매트랩과 그래프

매트랩 내장 삼각 함수

함 수

( 단위 : 라디안 ) 예

함수

( 단위 : 도, ° ) 예

sin (x) >> sin (pi/2)

ans = 1 sind (x)

>> sind ( 90 )

ans = 1

cos (x) >> cos (pi/3)

ans = 0.5 cosd (x)

>> cosd ( 60 )

ans = 0.5

tan (x) >> tan (pi/3)

ans = 1.7321 tand (x)

>> tand ( 60 )

ans = 1.7321

Page 43: 매트랩과 그래프

매트랩 내장 근사화 함수

함 수 설 명 예

round(x) 반올림 계산 >> round(1.98)

ans = 2

fix(x) 0 에 가장 가까운 정수 계산 >> fix(2.98)

ans = 2

ceil(x) 올림 함수 >> ceil(3.06)

ans = 4

floor(x) 내림 함수 >> floor(-3.999)

ans = -4

rem (x, y) x ÷ y 의 나머지를 계산 >> rem (27, 4)

ans = 3

Page 44: 매트랩과 그래프

신호 및 시스템과 매트랩

- 이산 신호 그리기

- 컨볼루션

- 상관 관계

Page 45: 매트랩과 그래프

단위 임펄스 함수

Page 46: 매트랩과 그래프

단위 임펄스 δ[n] 그리기

>> n = [ -3 : 10 ];

>> x = [ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

>> stem(n, x);

>>

Page 47: 매트랩과 그래프

단위 임펄스 δ[n- n0] 그리기

>> n = [ -3 : 10 ];

>> x = [ (n-4)==0];

>> stem(n, x);

>>

Page 48: 매트랩과 그래프

단위 계단 함수 : u[n]

Page 49: 매트랩과 그래프

단위 계단 함수

>> n = [ -8 : 20 ];

>> x = [ n>=0];

>> stem(n, x);

>>

>> n = [ -8 : 20 ];

>> x = [ n-5>=0];

>> stem(n, x);

>>

지연된 단위 계단 : u[n-n0]

Page 50: 매트랩과 그래프

지연된 단위 계단 함수 : u[n-5]

Page 51: 매트랩과 그래프

단위 램프 함수 : r[n]

Page 52: 매트랩과 그래프

단위 램프 함수

>> n = [ -8 : 20 ];

>> x = [ n>=0.*n];

>> stem(n, x);

>>

Page 53: 매트랩과 그래프

지수 (감소) 함수 : e-n

>> n = [ -8 : 20 ];

>> x = [ (n>=0).*(exp(-0.5*n)];

>> stem(n, x);

>>