데이터를 수집하고, 계산을 통해 얻은 결과는 이미 있다는 전제하에
이를 그래프(이미지)로 보다 잘 표현하기 위한 방법을 소개하려고 합니다.
http://downrg.com/249, http://downrg.com/250
위 게시물도 같이 참고하면 도움이 될 것 같습니다.
내용이 비슷할 수 있으나 이번에 올리는 글들은 보다 실용적으로 사용하기 위한
방향으로 정리해보겠습니다.

---------------------------------------------------------------------------

1. Figure 창의 도구(Toolbar)

사용자 삽입 이미지
< Camera 도구를 제외한 모든 도구를 표시한 Figure 화면 >

기본적으로 View->Figure Toolbar가 표시되어 있습니다.
이 도구에는 새로운 figure창을 만든다거나, figure 결과물을 fig 또는 이미지로 저장하기 위한
도구버튼들이 포함되어 있습니다.
도구의 모양만을 보고 기능을 추측할 수는 있지만 그중에 유용한 도구들 몇개만 설명하자면~

먼저 Data Cursor 도구  가 있습니다. Figure에 나타낸 그래프는 기본으로 결과값이 표시되지 않습니다.
따라서 특정 위치의 값을 보려고 할 때 사용하는 도구 입니다.
도구를 선택하고 그래프를 선택 또는 드래그를 하면 해당 위치의 값을 알 수 있습니다.
Alt키를 누른 상태에서 클릭을 할 경우 여러 군데에 데이터 값을 표시 할 수 있습니다.
(마우스 우측 버튼를 누르고 Create New Datatip을 선택하셔도 됩니다.)
반대로 지울 때는 Datatip을 선택하고 delete키를 누르면 됩니다.

그래프를 한 화면에 여러개 표시하게 될 경우 범례가 필요합니다.
 버튼을 선택하면 자동으로 범례를 표시할 수 있습니다.
범례 항목의 이름은 마우스 커서 버튼이 선택된 상태에서
그래프를 선택하고 Display Name을 수정해주면 자동으로 업데이트 됩니다.
(아래 첨부한 < Figure - Property Editor 창 화면 > 그림 참조)

다음으로  버튼은 Plot tool들을 보이거나 감추는 도구입니다.
버튼을 클릭하게 되면 지정한 툴들이 보여지게 되고, 반대로 옆에 버튼을 누르면
모든 tool들이 숨김 상태가 됩니다.

기본 도구(Figure Toolbar)에서 마우스 커서 버튼을 누르고 그래프를 선택한다음
마우스 우측 버튼을 누르게 되면 아래와 같은 화면을 볼 수 있습니다.

사용자 삽입 이미지

그래프의 색을 변경할 수도 있고, 선의 굵기, 선의 모양,
마커의 모양이나 크기등을 고칠 수 있습니다.
하지만 이렇게 적용한 값은 m-file로 작성한 코드가 아니기 때문에
같은 그래프를 다시 plot할 때 속성이 지워집니다.

따라서 자신이 설정한 값들을 나중에 다시 사용하기 위해서는
이 값들 code로 작성할 필요가 있습니다.
이 때는 Show M-Code 버튼을 눌러서 자신이 정한
속성에 대한 코드를 볼 수 있습니다.

Show Property Editor 기능을 이용하면 위에 나온 속성들을 별도의 창을 통해
설정할 수 있습니다. 데이터의 형태에 따라서 Plot type을 바로 수정할 수도 있습니다.
그래프 함수의 속성등을 전부 알고 있기는 어렵기 때문에 Property editor를 통해
속성들을 적용시키고 위에서 말한 Show M-Code를 통해
code를 작성하는 것도 편리한 방법이라고 생각됩니다.

사용자 삽입 이미지
< Figure - Property Editor 창 화면 >

<참고> Figure 함수와 관련된 Property
m-file내에서 여러 plot을 다른 창에 표시하려고 할 때 figure 함수를 사용하게 됩니다.
그냥 figure라고 입력하여도 새로운 창이 생성되지만, 보다 보기 좋게 하기 위해서는
추가적인 코드가 필요합니다. 창의 이름을 설정하고, 창의 번호 표시, 위치 등을 설정할 수 있습니다.
figure('Name','창이름','Numbertitle','On 또는 Off','Position',[left, bottom, width, height])


2. 그래프와 관련된 함수 목록 정리
  ㄱ. 2-D 그래프 함수 종류

     - Line Graphs: plot, plotyy, loglog, semilogx, semilogy, stairs, contour, ezplot, ezplot, ezcontour
     - Bar Graphs: bar, barh, hist, pareto, errorbar, stem
     - Area Graphs: area, pie, fill, contourf, image, pcolor, ezcontourf,
     - Direction Graphs: feather, quiver, comet
     - Radial Graphs: polar, rose, compass, ezpolar
     - Scatter Graphs: scatter, spy, plotmatrix

사용자 삽입 이미지
  ㄴ. 3-D 그래프 함수 종류
     - Line Graphs: plot3, contour3, contourslice, explot3, waterfall
     - Mesh Graphs and Bar Graphs: mesh, meshc, meshz, ezmesh, stem3, bar3, bar3h
     - Area Graphs and Constructive Objects: pie3, fill3, patch, cylinder, ellipsoid, sphere
     - Surface Graphs: surf, surfl, surfc, ezsurf, ezsurfc,
     - Direction Graphs: quiver3, comet3, streamslice
     - Volumetric Graphs: scatter3, coneplot, streamline, streamribbon, streamtube

사용자 삽입 이미지
* 자료출처: MATLAB User Guide

---------------------------------------------------------------------------
다음에 정리하려고 하는 내용은 그래프의 데이터 값을 보다
알아보기 쉽게 하기 위한 Annotating과 관련된 기능들과 함수들을 정리할 예정입니다.
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2009/12/18 21:35 2009/12/18 21:35

Leave a comment
[로그인][오픈아이디란?]

Sketching a Root Locus

1. - Root Locus는 Pole에서 출발해서 Zero에서 끝난다.
    - Pole의 수가 Zero의 수보다 많은 경우 나머지는 발산한다.
       (Parameter K는 0부터 무한대 까지의 값을 갖는다.)

2. - Phase Condition을 만족하는 Root Locus를 Real Axis에 그린다.
    - Real Axis위에 위치하지 않은 Pole과 Zero를 고려하지 않는 이유는 켤레 복소수이기 때문에
       둘의 Phase를 더하면 360도 이기 때문이다.
    - Real Axis에서 Root Locus를 찾는 요령은 Testing Point를 기준으로 오른쪽에 위치한
      Zero와 Pole의 개수의 합이 홀수이면 된다. 그 이유는 왼쪽에 위치한 Pole과 Zero는 Phase가 '0'도이기
      때문에 오른쪽에 있는 Zero와 Pole만 고려하면 되고, 그 개수가 홀수 일 때 180도이다.
   
3. - 발산하는 Pole의 점근선의 중심 위치와 각도를 계산해서 점근선을 그린다.
    - 점근선 각도와 중심 (n은 분모의 차수, m은 분자의 차수)
                            ,

4. - 하나의 Pole을 기준으로 출발각(Angle of departure)과 도착각(Angle of arrival)을 계산하여
      Pole의 이동 방향을 계산한다. 아래 식의 q는 기존 Pole에서 상대적으로 떨어진 거리를 의미한다.(1=제자리)
    - 출발각(도착각)을 알고 싶은 pole을 향해 다른 pole과 zero에서 벡터를 그리고 그 벡터가 이루는 각을 구한다.
     

5. - Pole이 LHP에서 RHP를 지나 Imaginary Axis를 지나는 점은 Routh's test를 이용해서
      K값을 찾고 그 때의 Imaginary 값을 구한다.

6. - Breakaway(or Breakin point): 전달함수의 분자를 a(s), 분모를 b(s)라고 했을 때 Ka(s)=-b(s)가 된다.
      (위와 같이 식이 나오는 이유는 Unit Feedback에서 특성 방정식이 1+Ka(s)/b(s)=0 이기 때문이다.)
      K에 대한 식(-b(s)/a(s))을 s에 대해서 미분한 값이 '0'이 되는 경우가 Breakaway 또는 Breakin point이다.
    - 특히 이 점은 s에 대해서 K의 값이 Max(Breakaway) 또는 Min(Breakin) 값에 해당한다.
    - 수식으로 표현하면 아래와 같다.
         

예제>
      
 

1. Pole의 위치는 0, -2, -1±2i, Zero는 없음. 따라서 4개의 Pole은 모두 발산할 것이다.

2. Real Axis 상에 있지 않은 -1±2i의 위상의 합은 360도 이므로, 무시하고 0과 -2 Pole을 기준으로
   Phase Condition을 만족시키는 영역이 Root Locus이다. 찾는 방법은 Test Point를 기준으로 우측에
   위치한 Pole과 Zero의 수의 합이 홀수개 이면 위상의 합이 180도 이다. 따라서 -2부터 0 구간이다.(아래 그림)

3. 점근선의 각도는 m이 0이고, n은 4이므로 ±45도, ±135도이다. 점근선의 중심은 α=(-2-1+2i-1-2i)/4=-1이다.

사용자 삽입 이미지
4. -1+2i에서의 출발각을 계산하면, Zero가 없으므로 -1+2i와 다른 Pole사이의 각을 구하면 된다.(l=0, q=1)
    0에서 그은 벡터가 이루는 각은 atan(2/-1), -2에서 이루는 각은 atan(2/1), -1-2i와 이루는 각은 90도 이다.
    같은 방식으로 출발각과 도착각을 계산할 수 있다.
   

5. Routh's Test를 이용해서 K를 구하면 16.25가 나오고, ω=±j1.58이 구해진다.(계산 과정 생략)

6. Beakaway Point(또는 Breakin Point)는 위의 공식에 의해 얻어지고, 그 값은 -1, -1±i1.22 이다.(계산 과정 생략)
사용자 삽입 이미지
사용자 삽입 이미지
< 최종 Root Locus >


*참고: Feedback Control of Dynamic Systems 5E

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/11/11 12:27 2008/11/11 12:27

Leave a comment
[로그인][오픈아이디란?]

LTIVIEW - LTI Viewer GUI

LTIVIEW opens an empty LTI Viewer.
The LTI Viewer is an interactive graphical user interface (GUI) for analyzing the time and frequency
responses of linear systems and comparing such systems.
See LTIMODELS for details on how to model linear systems in the Control System Toolbox.

LTIVIEW(PLOTTYPE,SYS1,SYS2,...,SYSN) further specifies which responses to plot in the LTI Viewer. PLOTTYPE may be any of the following strings (or a combination thereof):
         1) 'step'           Step response
         2) 'impulse'        Impulse response
         3) 'lsim'           Linear simulation plot
         4) 'initial'        Initial condition plot
         5) 'bode'           Bode diagram
         6) 'bodemag'        Bode Magnitude diagram
         7) 'nyquist'        Nyquist plot
         8) 'nichols'        Nichols plot
         9) 'sigma'          Singular value plot
        10) 'pzmap'          Pole/Zero map
        11) 'iopzmap'        I/O Pole/Zero map

<example>

t=tf(1,[1,2,8]) %s^2 + 2 s + 8
ltiview(t)

사용자 삽입 이미지
1. 화면 구성 설정 : 'Edit -> Plot Configurations'
   - 화면 구성을 어떻게 나눌 것인지 설정하고, 각 부분에서 보일 항목을 선택

2. LTI Viewer 설정 : 'Edit -> Viewer Preferences' - 단위, 폰트나 색상, Simulation 구간 등 설정

3. 특성 보기 : 각 Plot 에서 마우스 우측 버튼을 누르고, 'Characteristics' 선택 후 아래 내용중 표시할 내용 지정
                   ('Peak Response', 'Settling time', 'Rise time', 'Steady state' 등...)
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/10/16 19:53 2008/10/16 19:53

Leave a comment
[로그인][오픈아이디란?]

Effect of Zeros and Poles

* Transfer Function
,
wn=2, jeta=1/2

1. Additonal Zeros



2. Additonal Poles


크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/10/04 14:41 2008/10/04 14:41

Comments List

  1. 하언수 2008/10/08 00:40 # M/D Reply Permalink

    오 이거 완전 맘에 드는거네용

Leave a comment
[로그인][오픈아이디란?]

Fourier series of Sawtooth wave

사용자 삽입 이미지
사용자 삽입 이미지
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/10/03 20:43 2008/10/03 20:43

Leave a comment
[로그인][오픈아이디란?]

Dirac delta Function Approximation

DIRAC(X) is zero for all X, except X == 0 where it is infinite.
     DIRAC(X) is not a function in the strict sense, but rather a distribution with
     int(dirac(x-a)*f(x),-inf,inf) = f(a) and diff(heaviside(x),x) = dirac(x).

Dirac.m
function Y = dirac(X)
Y = zeros(size(X));
Y(X == 0) = Inf;

< Approximate Dirac delta Function >
사용자 삽입 이미지
< Matabl Promgram Source >

< Figure >
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/09/21 23:32 2008/09/21 23:32

Leave a comment
[로그인][오픈아이디란?]

Dirichlet Kernel

정의:


특성:


기본함수:(matlab 내장)
function y=diric(x,N)
  error(nargchk(2,2,nargin,'struct'));
  if round(N) ~= N || N < 1 || numel(N) ~= 1,
      error(generatemsgid('MustBePosInteger'),'Requires N to be a positive integer.');
  end

  y=sin(.5*x);
  i=find(abs(y)>1e-12);   % set where x is not divisible by 2 pi
  j=1:length(x(:));
  j(i)=[];                         % complement set
  y(i)=sin((N/2)*x(i))./(N*y(i));
  y(j)=sign(cos(x(j)*((N+1)/2)));

그래프:
t=[-3*pi:0.01:3*pi];
y=5*diric(t,5);y2=11*diric(t,11);
hold on
plot(t,y,'b-'), plot(t,y2,'r')
axis([-3*pi,3*pi,-5,12]), title('Dirichlet Kernel Function'), grid on
legend('diric(t,5)','diric(t,11)')
hold off

* 참고: http://en.wikipedia.org/wiki/Dirichlet_kernel

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/09/07 10:22 2008/09/07 10:22

Leave a comment
[로그인][오픈아이디란?]

Sinc Function

정의:


특성: (표준화한 sinc 함수에서) x가 0을 제외한 정수값일 때 0을 지남. x가 0일 때는 1값을 가짐.
        x가 0일 때는 l'Hospital's 정리를 이용하여 값을 구할 수 있음. 면적의 합은 1.

기본함수:(matlab 내장)
function y=sinc(x)
  i=find(x==0); % x값이 0일 때의 index 번호를 i에 저장
  x(i)= 1;        % From LS: don't need this is /0 warning is off
  y = sin(pi*x)./(pi*x);
  y(i) = 1;       % x가 0일 때 y값은 1로 지정 by l'Hospital's Theorem

그래프:
x=[-5:0.1:5];y=sinc(x);y2=sinc(x).^2;
xl=[-1,0,1];yl=[0,1,0];
hold on
plot(x,y), plot(x,y2,'r'), grid on, axis([-5,5,-0.5,1.5])
line(xl,yl,'color','k','linestyle','-.')
title('Normalized Sinc Function Graph')
legend('sinc(x)','sinc^2(x)')
hold off

사용자 삽입 이미지
* 참고: http://en.wikipedia.org/wiki/Sinc_function

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/09/06 22:21 2008/09/06 22:21

Leave a comment
[로그인][오픈아이디란?]

Time response - 시간 응답

1. Step
 
    - 함수 구문: 
           step(sys)
           step(sys,t)
           step(sys1,sys2,...,sysN,t)
           [y,t] = step(sys)
 
    - 예제 1: 
           a = [-0.5572   -0.7814;0.7814  0];
           b = [1 -1;0 2];
           c = [1.9691  6.4493];
           sys = ss(a,b,c,0);
           step(sys)

사용자 삽입 이미지
     - 예제 2: 
           num = 25;
           den = [1,4,25];
           H = tf(num, den);
           step(H);
사용자 삽입 이미지
2. Impulse

     - 함수 구문: 
           impulse(sys,t)
           impulse(sys1,sys2,...,sysN,t)
           [y,t] = impulse(sys)

     - 예제: 
           (step 예제 1의 코드와 동일하며 step 함수 대신에 impulse 사용)
           impulse(sys)
사용자 삽입 이미지
3. Initial

     - 함수 구문: 
           initial(sys,x0)
           initial(sys,x0,t)

     - 예제: 
           a = [-0.5572   -0.7814;0.7814  0];
           c = [1.9691  6.4493];
           x0 = [1 ; 0];                                   %Initiala Condition
           sys = ss(a,[],c,[]);
           initial(sys,x0)
사용자 삽입 이미지

4. Lsim

     - 함수 구문: 
           lsim(sys,u,t)
           lsim(sys,u,t,x0)
           lsim(sys,u,t,x0,'zoh')
           lsim(sys,u,t,x0,'foh')

     - 예제: 
           [u,t] = gensig('square',4,10,0.1);
           H = [tf([2 5 1],[1 2 3]) ; tf([1 -1],[1 1 5])]
           lsim(H,u,t)

사용자 삽입 이미지
* 참고: Matlab Documents

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/07/06 12:24 2008/07/06 12:24

Leave a comment
[로그인][오픈아이디란?]

화학 원소 주기율표

 

사용자 삽입 이미지

 원소 주기율표를 matlab을 이용하여 작성하는 코드입니다.
사각형을 그리고 각 원소의 번호와 기호, 질량, 이름을 표시하게 됩니다.

원래 과제는 저것보다 더 많은 원소에 대한 정보를 표시하는 것이지만,
코드를 간략화 해서 질량과 영문 이름만 표시하도록 정리하였습니다.

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/07/02 00:31 2008/07/02 00:31

Leave a comment
[로그인][오픈아이디란?]
clear;clf;cla reset;                                 % 초기화
X=[0 1 1 0];                                          % 개미 각각의 초기 X 좌표
Y=[0 0 1 1];                                          % Y 좌표
Z=[0 1 0 1];                                          % Z 좌표
r=[X;Y;Z];                                            % 개미들의 위치
v=0.01;                                                 % 속도
track=r;                                                % 개미의 위치 변화
tmax=400;                                            % 최대 시간
color=char('or','hb','+','d');                   % 표시 형식

hold on
for t=2:tmax
    direction=r(:,[2 3 4 1])-r(:,[1 2 3 4]);   % 방향 벡터
    udir=direction/norm(direction(:,1));     % 단위 벡터
    r=r+v*udir;                                        % 위치 계산
    if norm(r(:,1)-[0.5;0.5;0.5]) < 0.01       % 중앙 위치에 가까워지면 종료.
        break;
    end
    track(:,:,t)=r;                                     % 좌표를 track에 저장
end

for m=1:4                                              %SQUEEZE Remove singleton dimensions
    x(:,m)=squeeze(track(1,m,:));y(:,m)=squeeze(track(2,m,:));z(:,m)=squeeze(track(3,m,:));
end

plot3(x,y,z)                                           % 입체로 그래프 그림

for m=1:4                                               % 개미를 좌표에 표시
    p(m)=plot3(x(1,m),y(1,m),z(1,m),color(m));
end

view(3)                                                 % 입체로 보기
grid on;                                                 % 눈금선 표시

for t=1:length(x(:,1))                                % 개미의 이동을 애니메이션 처럼 표시
    for m=1:4
        set(p(m),'XData',x(t,m),'YData',y(t,m),'ZData',z(t,m))
    end
    drawnow
end
hold off 
사용자 삽입 이미지
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/07/01 23:07 2008/07/01 23:07

Leave a comment
[로그인][오픈아이디란?]

Laplace - 라플라스 변환

사용자 삽입 이미지
피에르 시몽 마르키 드 라플라스 - 프랑스 수학자
   (Pierre-Simon, Marquis de Laplace, 1749년 3월 23일 - 1827년 3월 5일)
  《천체역학》, 《확률론의 해석이론》등의 명저를 남겼으며, 라플라스 변환, 라플라스
  방정식 등에 그의 이름이 남아있다. 귀족집안에서 태어났으며, 1765년부터 칸의 한 예수회
  계열 대학에서 공부했다. 1771년부터는 파리 군관학교에서 교편을 잡았다. 나폴레옹 보나
  파르트가 그의 제자 중 한명이다. 1773년 파리 아카데미의 회원이 되며, 1788년 마리 샤를
  로트와 결혼한다. 1799년엔 내무부 장관으로 발탁된다.

1. 라플라스 변환

    L = LAPLACE(F) is the Laplace transform of the scalar sym F with default independent variable t.
   The default return is a function of s.  If F = F(s), then LAPLACE returns a function of t:  L = L(t).
   By definition L(s) = int(F(t)*exp(-s*t),0,inf), where integration occurs with respect to t.

    L = LAPLACE(F,t) makes L a function of t instead of the default s:
    LAPLACE(F,t) <=> L(t) = int(F(x)*exp(-t*x),0,inf).
 
    L = LAPLACE(F,w,z) makes L a function of z instead of the
    default s (integration with respect to w).
    LAPLACE(F,w,z) <=> L(z) = int(F(w)*exp(-z*w),0,inf).
 
    Examples:
       syms a s t w x
       laplace(t^5)           returns   120/s^6
       laplace(exp(a*s))      returns   1/(t-a)
       laplace(sin(w*x),t)    returns   w/(t^2+w^2)
       laplace(cos(x*w),w,t)  returns   t/(t^2+x^2)
       laplace(x^sym(3/2),t)  returns   3/4*pi^(1/2)/t^(5/2)
       laplace(diff(sym('F(t)')))   returns   laplace(F(t),t,s)*s-F(0)

2. 역라플라스 변환

    ILAPLACE Inverse Laplace transform.
    F = ILAPLACE(L) is the inverse Laplace transform of the scalar sym L with default independent variable s.
    The default return is a function of t.  If L = L(t), then ILAPLACE returns a function of x: F = F(x).
    By definition, F(t) = int(L(s)*exp(s*t),s,c-i*inf,c+i*inf) where c is a real number selected so that all
   singularities of L(s) are to the left of the line s = c, i = sqrt(-1), and the integration is taken with respect to s.
 
    F = ILAPLACE(L,y) makes F a function of y instead of the default t:
        ILAPLACE(L,y) <=> F(y) = int(L(y)*exp(s*y),s,c-i*inf,c+i*inf).
    Here y is a scalar sym.
 
    F = ILAPLACE(L,y,x) makes F a function of x instead of the default t:
    ILAPLACE(L,y,x) <=> F(y) = int(L(y)*exp(x*y),y,c-i*inf,c+i*inf),
    integration is taken with respect to y.
 
    Examples:
       syms s t w x y
       ilaplace(1/(s-1))              returns   exp(t)
       ilaplace(1/(t^2+1))            returns   sin(x)
       ilaplace(t^(-sym(5/2)),x)      returns   4/3/pi^(1/2)*x^(3/2)
       ilaplace(y/(y^2 + w^2),y,x)    returns   cos(w*x)
       ilaplace(sym('laplace(F(x),x,s)'),s,x)   returns   F(x)

3. 부분분수 전개

    RESIDUE Partial-fraction expansion (residues).
    [R,P,K] = RESIDUE(B,A) finds the residues, poles and direct term of a partial fraction expansion of
    the ratio of two polynomials B(s)/A(s).
    If there are no multiple roots,

       B(s)       R(1)       R(2)             R(n)
       ----  =  -------- + -------- + ... + -------- + K(s)
       A(s)     s - P(1)   s - P(2)         s - P(n)

    Vectors B and A specify the coefficients of the numerator and denominator polynomials in descending
    powers of s.  The residues are returned in the column vector R, the pole locations in column vector P,
    and the direct terms in row vector K.  The number of poles is n = length(A)-1 = length(R) = length(P).
    The direct term coefficient vector is empty if length(B) < length(A),
    otherwise length(K) = length(B)-length(A)+1.

* 참고: http://en.wikipedia.org/wiki/Laplace_transform
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/07/01 00:36 2008/07/01 00:36

Leave a comment
[로그인][오픈아이디란?]

Nyquist Plot - 나이퀴스트 선도

A Nyquist plot is used in automatic control and signal processing for assessing the stability of a system with feedback. It is represented by a graph in polar coordinates in which the gain and phase of a frequency response are plotted. The plot of these phasor quantities shows the phase as the angle and the magnitude as the distance from the origin. This plot combines the two types of Bode plot — magnitude and phase — on a single graph, with frequency as a parameter along the curve. The Nyquist plot is named after Harry Nyquist, a former engineer at Bell Laboratories.

Assessment of the stability of a closed-loop negative feedback system is done by applying the Nyquist stability criterion to the Nyquist plot of the open-loop system (i.e. the same system without its feedback loop). This method is easily applicable even for systems with delays which may appear difficult to analyze by means of other methods.

Nyquist and related plots are classic methods of assessing stability, but have been supplemented or supplanted by computer-based mathematical tools in recent years. Such plots remain a convenient method for an engineer to get an intuitive feel for a circuit.

< MATLAB 함수 설명 >

  - nyquist(sys) : plots the Nyquist response of an arbitrary LTI model sys.

  - nyquist(sys,w) : explicitly specifies the frequency range or frequency points to be used for the plot.
                                 To focus on a particular frequency interval, set w = {wmin,wmax}

  - nyquist(sys1,sys2,...,sysN) or nyquist(sys1,sys2,...,sysN,w)
                : superimposes the Nyquist plots of several LTI models on a single figure.
                  You can also specify a distinctive color, linestyle, and/or marker for each system plot
                   with the syntax nyquist(sys1,'PlotStyle1',...,sysN,'PlotStyleN')

      When invoked with left-hand arguments return the real and imaginary parts of the frequency
      response at the frequencies w (in rad/sec)
             [re,im,w] = nyquist(sys)   or   [re,im] = nyquist(sys,w)

< 예제 코드 및 출력 결과>

    - Plot the Nyquist response of the system
       

사용자 삽입 이미지
      Code: >> H = tf([2 5 1],[1 2 3])                           >> nyquist([2 5 1], [1 2 3])
               >> nyquist(H)                       또는             >> grid
               >> grid

* 참고: http://en.wikipedia.org/wiki/Nyquist_plot
          http://www.prosoundweb.com/install/sac/n26_4/nyquist/nyquist.shtml

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/06/30 15:23 2008/06/30 15:23

Leave a comment
[로그인][오픈아이디란?]

Bode Plot - 보데 선도

사용자 삽입 이미지
A Bode plot, named after Hendrik Wade Bode, is usually a combination of a Bode magnitude plot and Bode phase plot:
  A Bode magnitude plot is a graph of log magnitude versus frequency, plotted with a log-frequency axis, to show the transfer function or frequency response of a linear, time-invariant system.
  A Bode phase plot is a graph of phase versus frequency, also plotted on a log-frequency axis, usually used in conjunction with the magnitude plot, to evaluate how much a frequency will be phase-shifted.

1. MATLAB을 이용한 Bode Plot

     - 사용 함수
        tf (전달함수) : sys = tf(num,den,Ts), tfsys = tf(sys)
        bode(보데선도) :  bode(sys1,sys2,...,sysN,w), bode(sys1,'PlotStyle1',...,sysN,'PlotStyleN')
        sym2poly : Symbolic-to-numeric polynomial conversion

     - 예제 : 아래 함수에 대한 Bode plot을 그려라.
       
사용자 삽입 이미지
        < 작성코드 >
          syms s                                     %Symbol로 s를 정의
          num = sym2poly(-100*(1+s));      %분모 항의 계수값
          den = sym2poly((1+s/10)*(1+s/1e5)*(1+s/1e7)); %분자 항의 계수값
          sys = tf(num,den);                     %전달함수 생성 (위 함수 식의 전개형태가 됨)
          bode(sys,{0.1,1e9})                   %bode plot
          grid on                                      %눈금자 표시

        < 출력 결과 >
사용자 삽입 이미지
     - 추가내용 : phase margin, gain margin
        margin() - MARGIN  Gain and phase margins and crossover frequencies.
        [Gm,Pm,Wcg,Wcp] = MARGIN(SYS)
        [Gm,Pm,Wcg,Wcp] = MARGIN(MAG,PHASE,W)
       
        위에서 작성한 num값과 den 값을 이용하여, 'margin(num,den)'를 실행하면 아래와 같은 결과를 얻음.

사용자 삽입 이미지
2. EXCEL을 이용한 Bode Plot
     - 사용 함수 : LOG(숫자) - 로그값, ROW(주소) - 행번호, COMPLEX(실수부,허수부) - 복소수,
                       IMPRODUCT(복소수,..., 복소수) - 복소수 곱셈, IMDIV(복소수1, 복소수2) - 복소수 나눗셈
                       IMABS(복소수) - 복소수의 크기, IMARGUMENT(복소수) - 복소수의 위상 라디안
                       IMREAL(복소수) - 실수부, IMAGINARY(복소수) - 허수부
                       DEGREES(라디안) - 각도변환

     - 작성 과정 (자세한 과정은 참고 내용중 3번째 홈페이지를 참고)
        1. 그래프로 그릴 최소값과, 최대값을 특정 셀에 입력
        2. 각주파수(w)를 log 단위로 100 등분 또는 그 이상으로 나누어 x축의 값을 만든다.
        3. w값에 대한 Magnitude를 계산하는 식을 세워서 하나의 y축 값을 설정한다.
        4. w값에 대한 Phase를 계산하는 식을 세워서 또다른 하나의 y축 값을 설정한다.
        5. Magnitude와 Phase에 대한 그래프를 각각 표현한다.
         * 작성한 셀의 내용:
            함수식 : =IMDIV(COMPLEX(-100,-100*B9),IMPRODUCT(COMPLEX(1,B9/10),
                                   COMPLEX(1,B9/100000),COMPLEX(1,B9/10000000)))
            Magnitude : =20*LOG(IMABS(C9))
            Phase : =DEGREES(IF(ATAN2(IMREAL(C9),IMAGINARY(C9))<0,ATAN2(IMREAL(C9),
                                         IMAGINARY(C9))+2*PI(),ATAN2(IMREAL(C9),IMAGINARY(C9))))
         (사용한 식은 절대적인 것은 아닙니다. 그리고 복소수에 대한 함수는 Excel 버젼에 따라 없을 수 있습니다.)

     - 출력 결과

사용자 삽입 이미지
* 참고 : http://en.wikipedia.org/wiki/Bode_plot
           http://www.ele.uri.edu/Courses/ele343/tutorials/matlab.bode.plots/
           http://www.chem.mtu.edu/~tbco/cm416/freqexcel.html

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/06/26 23:29 2008/06/26 23:29

Leave a comment
[로그인][오픈아이디란?]

% 앞의 개미의 방향을 따라 일정한 속력으로 이동하는 개미의 궤적

X=[0 0 1 1];                                 % X 좌표
Y=[0 1 1 0];                                 % Y 좌표
r=[X;Y];
v=0.0005;                                    % 개미의 이동 속도
track=r;                                     % 초기 위치 좌표
tmax=10000;                                  % 최종 시간
color=char('or','hb','+','d');               % 4마리 개미 표시 설정

for t=2:tmax
    direction=r(:,[2 3 4 1])-r(:,[1 2 3 4]); % 앞의 개미에서 자신의 위치를 계산한 방향
    udir=direction/norm(direction(:,1));     % 방향 단위 벡터
    r=r+v*udir;                              % 속도에 방향을 곱하여 위치 계산
    if norm(r(:,1)-[0.5;0.5]) < 0.01         % 개미가 중앙에 오면 break 명령
        break;
    end
    track(:,:,t)=r;                          % 개미 4마리의 위치를 track에 저장
end

t=1;                                         % 값 초기화
x=[];y=[];
for m=1:4                                    % 각 개미의 x,y 좌표를 track으로 부터 계산
    x(:,m)=squeeze(track(1,m,:));
    y(:,m)=squeeze(track(2,m,:));
end

clf                                          % 기존 이미지를 지우고 재설정
cla reset;
hold on                                      % 이미지 유지 on
plot(x,y)                                    % 개미의 궤적을 그림
for m=1:4                                    % 개미 4마리를 초기 위치에 표시
    p(m)=plot(x(1,m),y(1,m),color(m),'EraseMode','xor');
end

for t=1:length(x(:,1))                       % 시간의 변화에 따라 set을 이용하여 개미 위치 변화
    for m=1:4
        set(p(m),'XData',x(t,m),'YData',y(t,m))
    end
    drawnow
end

axis([0 1 0 1])                              % x, y 축 설정
hold off

사용자 삽입 이미지

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/01/31 22:26 2008/01/31 22:26

Leave a comment
[로그인][오픈아이디란?]

Monte Carlo 적분

% Monte Carlo 적분 - 임의 수에 대해 반원 내에 들어가는 수를 측정하여 면적 계산

Nshoot=1000;                                                           % 발생시킬 임의 수의 개수
square=[0 0 1 1 0;0 1 1 0 0];                                      % 1행은 x좌표, 2행은 y좌표로 쓰일 예정
cla reset;                                                                % 축 재설정(초기화)

hold on                                                                   % Figure 유지
fill(square(1,:),square(2,:),'y');                                  % (0.0)부터 (1.1)을 지나 다시 돌아오는 영역, 노란색
t=0:0.1:pi/2;
[x,y]=pol2cart(t,repmat(1,size(t)));                            % 각좌표계로 표현된 반원을 직각좌표계로 변환
plot(x,y,'r')                                                             % 반원 그리기
sum=0;

for m=1:Nshoot                                                        % 임의수를 지정한 수만큼 반복
    x=rand; y=rand;                                                   % 임의수
    if norm([x y]) < 1                                                % x나 y에서 가장 큰 값이 1보다 작음, 반원내의 값 의미
        sum=sum+1;                                                   % 조건 만족시에 sum 값을 증가시킴
        plot(x,y,'.','MarkerSize',8)                               % 마커크기를 8로 좌표 표시
    end
end

area=sum/Nshoot;                                                  % 전체 임의 수의 개수에 대한 sum의 값으로 면적 계산
text(0.6,0.9,sprintf('Area (exact) = %.3g',pi/4));
text(0.6,0.95,sprintf('Area (Monte) = %.3g',area));  
set(gca,'xlim',[0 1])                                               % x축 제한
axis equal off
hold off

사용자 삽입 이미지

p.s. 위의 올리는 matlab 글들은 과학계산프로그래밍 수업때 교수님께서 사용하신 강의노트 내용입니다.
앞으로도 내용을 정리하고, 제가 주석을 달아서 올릴 예정입니다.
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/01/27 21:22 2008/01/27 21:22

Leave a comment
[로그인][오픈아이디란?]

Matlab 함수 요약 정리(완결)



학교에서 matlab을 이용 할 때마다 두꺼운 책을 보기에 불편함이 있어,
블로그를 통해 함수 요약정리하려고 한 것이 여기까지 오게 된 것 같습니다.

블로그에 있는 내용은 처음 글에서 밝힌 것처럼
'Matlab 입문과 활용 - 높이깊이'의 요약 부분입니다.

위 책에는 뒤쪽에 simulink와 진동해석, 제어시스템 설계 부분이 있는데,
이 부분은 아직 제가 모르는 부분이 많고, 블로그에서 다루기 복잡한 것 같습니다.
그래서 이 글을 마지막으로 함수 정리는 마지막이 될 것 같습니다.

앞으로 올리게 될 내용은 예전에 '과학계산 프로그래밍' 수업 때,
교수님께서 올려주신 강의노트를 바탕으로 몇 개의 글을 올릴 예정입니다.

그리고 대학교 수업을 통해 matlab을 이용한다면
그때마다 필요한 부분을 정리해서 올릴 계획입니다.

matlab에 관해 자세한 공부를 하고자 하는 분은
http://matlabschool.com/ 사이트를 방문하시면 도움이 될 것 같습니다.

아래 첨부파일은 지금까지 블로그에 올라온 내용입니다.
블로그에 글을 작성할 때 먼저 word를 이용하고 복사하는 식으로
작성하였기 때문에 아래 내용이 원본이라고 할 수 있습니다.
그런데 페이지 구성을 위해서 이미지가 하나 빠진 부분이 있고,
블로그의 내용과 약간 차이가 있을 수는 있습니다.
p.s. 부족한 matlab 글들을 읽어주신 분들께 감사드립니다.

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/01/23 22:50 2008/01/23 22:50

Comments List

  1. hoshi 2009/06/12 13:13 # M/D Reply Permalink

    감사합니다~_~ 잘보고 잘쓰겠습니다.

  2. 아늑살이 2009/06/29 21:11 # M/D Reply Permalink

    감사합니다. ^^*

  3. 매트랩초짜 2010/01/21 16:00 # M/D Reply Permalink

    감사합니다^^

Leave a comment
[로그인][오픈아이디란?]

13. 데이터 분석

가. 데이터 분석 함수
   - max(x): 최대값, min(x): 최소값, mean(x): 평균값, median(x): 중간값
   - sum(x): 합, prod(x): 누적곱, cumsum(x): 누적합, cumprod(x): 누적곱
   - sort(x): 정렬, var(x): 분산, std(x): 표준편차

나. 퓨리에 변환
fft(x)
    - Matlab 내의 doc fft 내용
    >>Fs = 1000;                    % Sampling frequency
    >>T = 1/Fs;                     % Sample time
    >>L = 1000;                     % Length of signal
    >>t = (0:L-1)*T;                % Time vector
    % Sum of a 50 Hz sinusoid and a 120 Hz sinusoid
    >>x = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
    >>y = x + 2*randn(size(t));     % Sinusoids plus noise
    >>subplot(121)
    >>plot(Fs*t(1:50),y(1:50))
    >>title('Signal Corrupted with Zero-Mean Random Noise')
    >>xlabel('time (milliseconds)')

    >>NFFT = 2^nextpow2(L); % Next power of 2 from length of y
    >>Y = fft(y,NFFT)/L;
    >>f = Fs/2*linspace(0,1,NFFT/2);

    % Plot single-sided amplitude spectrum.
    >>subplot(122)
    >>plot(f,2*abs(Y(1:NFFT/2)))
    >>title('Single-Sided Amplitude Spectrum of y(t)')
    >>xlabel('Frequency (Hz)')
    >>ylabel('|Y(f)|')

사용자 삽입 이미지

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/01/21 23:29 2008/01/21 23:29

Comments List

  1. ☆Mango  2009/07/20 16:26 # M/D Reply Permalink

    여기에 주어주신 FFT는 정현파 즉 아날로그 데이터에 대한

    FFT를 소개해 주신것 같은데요..

    혹시 변조된 후의 디지털 데이터에 대해 FFT를

    수행하는 방법에 대한 설명을 조금 더 들을 수 있을까요..?

    4개의 심볼, 1+j, 1-j, -1+j, -1-j로 변환된

    데이터열에 대한 fft나 ifft 에대해 궁금합니다~ (>_<)

    P.S.위에 보면.. t에 의해 나온 값들은 연속적이지 않은데요.. 이것을 디지털로 봐야 하는건가요~? 제가 아직 모르는게 많아서요.. 헤헤;;

    1. downright  2009/07/21 01:17 # M/D Permalink

      symbol을 통해 식을 도출한 것이 아니기 때문에,
      입력 신호가 물론 아날로그 신호식이지만, 시개별 값으로 불 수 있습니다.
      따라서 말슴하신 데이터 열을 이용해서 바로 fft 함수를 돌리시면 될 것 같은데요.

      >> X=[1+j, 1-j, -1+j, -1-j]
      Y=fft(X)
      ifft(Y)
      X =
      1.0000 + 1.0000i 1.0000 - 1.0000i -1.0000 + 1.0000i -1.0000 - 1.0000i
      Y =
      0 2.0000 - 2.0000i 0 + 4.0000i 2.0000 + 2.0000i

      ans =
      1.0000 + 1.0000i 1.0000 - 1.0000i -1.0000 + 1.0000i -1.0000 - 1.0000i

      단순하게 이렇게 되는 것으로 보입니다.
      계산하는 과정은 Discrete-Time FFT를 참고해보시면 될 것 같습니다.
      저도 신호를 전공하지는 않아서 설명이 어렵네요.
      아래 사이트를 통해 이론을 참고해보시거나. 4point 또는 8, 16point fft로 검색해서 찾아보세요.
      http://vada.skku.ac.kr/crazy/cwb-data/data/lecarch/final_report.ppt

      추가로 말씀 드리자면, 제가 올린 샘플의 왼쪽 그림은 시간에 대한 data값을 그린 것입니다. 이 그래프가 갖고 있는 주파수 성분들을 보기 위해서 fft를 한 것이구요. 이런걸 스펙트럼이라고 합니다.

  2. ☆Mango  2009/07/22 15:33 # M/D Reply Permalink

    귀중한 자료 감사드립니다
    조금더 공부해봐야 할것 같습니다~
    열심히 돌려보면서 말이죠~!! 흐흐흐~

Leave a comment
[로그인][오픈아이디란?]

12. 상미분 방정식

가. 함수
    - ode23: 2차 또는 3차의 Runge-Kutta method
                  (ODE23  Solve non-stiff differential equations, low order method)
    - ode45: 4차 또는 5차의 Runge-Kutta method
                  (ODE45  Solve non-stiff differential equations, medium order method)
    - 사용법: ode23(‘M-file’,time,Initial_Condition,Options), ode45(‘M-file’,time,Initial_Condition,Options)

나. 예제 - y’’=y’(1-y^2)-y의 해 구하기
    <m-file 내용>
       function U_prime=U_func5(x,u)
       U_prime=zeros(2,1);                                      % 변수를 0으로 초기화
       U_prime(1)=u(1)*(1-u(2)^2)-u(2);                    % 상태 변수를 사용한 1차 미분 방정식
       U_prime(2)=u(1);

    >>time=[0,30];                                                 % 시작과 끝점
    >>Initial_Condition=[0,0.1];                                % 초기조건 y(0)=0.1, y’(0)=0
    >>[x,Y]=ode45('U_func5',time,Initial_Condition);  % Y의 1열은 y’, 2열은 y를 의미
    >>dy=Y(:,1); y=Y(:,2);
    >>subplot(211); plot(x,dy); xlabel('x'); ylabel('dy')
    >>subplot(212); plot(x,y); xlabel('x'); ylabel('y')

사용자 삽입 이미지

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/01/20 11:46 2008/01/20 11:46

Leave a comment
[로그인][오픈아이디란?]

11. 라플라스 변환

가. 라플라스 변환laplace(F)
    예) >>syms t a b
         >>F=t^2+sin(a*t)-t*cos(b*t);
         >>L=laplace(F)
         L= 2/s^3+a/(s^2+a^2)-(s^2-b^2)/(s^2+b^2)^2
         >>pretty(L)
                                               2    2
                           2        a       s  - b
                          ---- + ------- - ----------
                            3     2     2      2    2  2
                           s     s  + a    (s  + b ) 


나. 역라플라스 변환
ilaplace(F)
    예) >>syms s a b
         >>L=2/s^3+a/(s^2+a^2)-(s^2-b^2)/(s^2+b^2)^2
         >>I=ilaplace(L)
         I= t^2+sin(a*t)-t*cos(b*t)

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/01/20 00:21 2008/01/20 00:21

Leave a comment
[로그인][오픈아이디란?]

10. 수치 미분과 적분

가. 미분diff(x)
    예) >>x=0:0.1:100;
         >>y=x.^2.*exp(-0.1*x)-x;
         >>subplot(1,3,1)
         >>plot(x,y)                    % x^2 그래프
         >>dy=diff(y)./diff(x);       % 차분법에 의한 미분
         >>dx=x(2:length(x));       % 차분법에 의해 x의 개수가 1개 줄어듦
         >>subplot(1,3,2)
         >>plot(dx,dy)                  % 1차 미분 그래프
         >>ddy=diff(dy)./diff(dx);   % 2차 미분
         >>ddx=dx(2:length(dx));   % dx보다 개수가 1개 줄어듦
         >>subplot(1,3,3)
         >>plot(ddx,ddy)               % 2차 미분 그래프
 

사용자 삽입 이미지

    [참고] 차분법에 의한 미분은 데이터 사이 간격이 충분히 조밀해야 오차가 작으므로,
              데이터 간격이 클 경우 보간법을 이용한 후 미분법 사용.

나. 적분
quad(‘M-file’,a,b,tol): simpson’s rule, quadl(‘M-file’,a,b,tol): Lobatto quadrature
                int(f,’x’): Symbolic 객체를 이용한 수식 적분, f를 x로 적분
      예제 1) <m-file 내용>
                 function y=func(x)
                   y=1./(1+x).^2;

                 >>quad('func',0,10)
                 ans = 0.909091053721440
                 >>quadl('func',0,10)
                 ans = 0.909090909256147
      예제 2) >>syms x                    % x를 symbolic로 지정
                 >>f=1/((1+x)^2);           % 함수식
                 >>int(f,'x')                   % symbolic 함수 적분
                 ans = -1/(1+x)
                 >>double(int(f,'x',0,10))    % 구간 0~10 에서 적분하고 값을 실수 변환
                 ans = 0.909090909090909

p.s. 만약 연산 결과의 소수 자리가 4자리만 표현되면, 'File' -> 'Preference...' -> 'Command Window' 에서
       Numeric Format을 long으로 바꾸면 됩니다.

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/01/19 11:24 2008/01/19 11:24

Leave a comment
[로그인][오픈아이디란?]

9. 다항식 연산, 해

가. 다항식 값 구하기polyval(배열연산), polyvalm(행렬연산)
    예) >>func=[1,-3,2,1];
         >>x=10;
         >>y=polyval(func,x) %x^3-3*x^2+2*x+1
         y= 721
         >>x2=[5,6,7];
         >>y2=polyval(func,x2)
         y2= 61, 121, 211
         >>x3=[1,2,3;4,5,6;7,8,9];
         >>y3=polyval(func,x3)
         y3=  1     1     7
             25    61   121
            211   337   505
         >>y4=polyvalm(func,x3) %Matrix must be square
         y4=  381         472         564
               872        1073        1272
             1364        1672        1981

나. 다항식의 산술 연산
-> + : 덧셈, - : 뺄셈, conv(a,b) : 곱셈, deconv(a,b) : 나눗셈,
                                       [R,P,K] = residue(f,g): 부분 분수 전개(R:나머지, P:극, K항)
    예) >>a=[1,2,3];                     예) >>f=[1,5,9,7];    % x^3+5*x^2+9*x+7
         >>b=[4,5,6];                          >>g=[1,3,2];     % x^2+3*x+2
         >>c= conv(a,b)                      >>[R,P,K]=residue(f,g)
         c= 4 13 28 27 18                      R= -1 ; 2
         >>deconv(c,a)                      P= -2 ; -1
         ans= 4, 5, 6                           K= 1 2           % -1/(x-(-2)) + 2/(x-(-1)) + x + 2

다. 다항식의 해 구하기
roots(coeff)
    예) >>func=[1,-3,-1,3];
         >>p=roots(func)
         p= 3.0000 ; 1.0000 ; -1.0000
    예) >>func=[1,-2,-3,4];
         >>s=roots(func)
         s= -1.6506         
             -0.1747 + 1.5469i
             -0.1747 - 1.5469i

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/01/09 11:13 2008/01/09 11:13

Leave a comment
[로그인][오픈아이디란?]

8. 보간법 및 회귀 분석

가. 선형 보간법 - interp1(x,y,x0), interp2(x,y,z,x0,y0)
    예) >>x=[40 48 56 64 72 80];
         >>y=[1.33 1.67, 2.08 2.36 2.71 3.19];
         >>plot(x,y,'o-')
         >>interp1(x,y,52)    %x값이 52일 때 y에 해당하는 값을 구함
         ans = 1.8750


 나. Cubic spline 보간법 - spline(x,y,x0)
    예) >>x=[40 48 56 64 72 80];
         >>y=[1.33 1.67, 2.08 2.36 2.71 3.19];
         >>x1=40:0.5:80;
         >>y1=spline(x,y,x1);
         >>plot(x,y,'o',x1,y1)
         >>spline(x,y,52)    %x값이 52일 때 y에 해당하는 값을 구함
         ans = 1.8860

 
다. 최소 자승법에 의한 곡선의 근사 - polyfit(x,y,1)
    예) >>x=[40 48 56 64 72 80];
         >>y=[1.33 1.67, 2.08 2.36 2.71 3.19];
         >>P=polyfit(x,y,1);
         >>plot(x,y,'o',x,P(1).*x+P(2))

 
라. 다항식을 사용한 회귀 곡선 - polyfit(x,y,N), polyval(P,x)
    예) >>x=[40 48 56 64 72 80];
         >>y=[1.33 1.67, 2.08 2.36 2.71 3.19];
         >>x1=40:0.5:80;
         >>P1=polyfit(x,y,2); %2차 다항식을 이용
         >>y1=polyval(P1,x1);
         >>P2=polyfit(x,y,5); %5차 다항식을 이용
         >>y2=polyval(P2,x1);
         >>plot(x,y,'o',x1,y1,x1,y2)

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/01/06 17:07 2008/01/06 17:07

Leave a comment
[로그인][오픈아이디란?]

7. 선형 연립 방정식의 해

가. 역행렬을 이용한 선형 연립 방정식의 해
    예) 3a+2b-c=10, -a+3b+3c=5, a-b-c=-1 의 해를 구하기
       >>A=[3,2,-1;-1,3,3;1,-1,-1];
       >>B=[10;5;-1];
       >>X=inv(A)*B
       X=1.000; 3.000; -1.000 % a, b, c

나. 행렬 나누기를 이용한 선형 연립 방정식의 해

    예) >>A=[3,2,-1;-1,3,3;1,-1,-1];
       >>B=[10;5;-1];
       >>X=A\B
       X=1.000; 3.000; -1.000 % a, b, c

다. 행렬의 삼각 분해를 이용한 선형 연립 방정식의 해

    예) >>[Lp,U]=lu(A);
       >>Y=inv(Lp)*B;
       >>X=inv(U)*Y;
       X=1.000; 3.000; -1.000 % a, b, c

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/01/06 15:17 2008/01/06 15:17

Leave a comment
[로그인][오픈아이디란?]

6. 행렬 연산

가. 전치 행렬transpose(A) 또는 A’, (ctranspose: 켤레 복소수의 전치 행렬)
    예) >> A=[1,2,3;4,5,6;7,8,9];
         >> transpose(A)
         ans = [1,4,7;2,5,8;3,6,9]

나. 역행렬inv(A)

다. 행렬식det(A)
    예) >> syms k1, k2, k3
         >> k = [(k1+k2+k3),-(k2+k3);-k3,(k2+k3)]
         k = [ k1+k2+k3,   -k2-k3]
              [      -k3,    k2+k3]
         >> det(k)
         ans = k1*k2+k1*k3+k2^2+k2*k3

라. 계수rank(A) : 원래 행렬의 행이나 열의 수에서 reduced row echelon form 행렬에서 행의
                            요소가 모두 0인 행의 수를 뺀 값. (rref : reduced row echelon form 행렬 생성)
   예) >> a=[1,-2,3;2,-5,1;1,-4,-7]
        >> rank(a)
        ans = 2
        >> rref(a)
        ans = [1,0,13;0,1,5;0,0,0] %rref에서 행의 요소가 모두 0인 행은 3행 뿐임.

마. tracetrace(A) : 행렬의 대각 요소의 합

바. 대각 행렬diag(A) : 대각 성분을 제외한 모든 요소가 0인 행렬

사. 삼각 인수 분해
     1. [L,U,P] = lu(A). (L: 하삼각 행렬, U: 상삼각 행렬, P:순열 행렬), PA = LU
     2. [Lp U] = lu(A). (Lp: permuted 하삼각 행렬, U: 상삼각 행렬), Lp = inv(P)*L

아. 직교 인수 분해 – [Q,R,E] = qr(A) (Q: unitary 행렬, R: 상삼각 행렬, E: 순열행렬), AE = QR

자. Cholesky 인수 분해 – [R,p,S] = chol(A) (R: 상삼각 행렬)

차. 고유치와 고유 벡터 – [X,lamda] = eig(A), (X: 고유벡터, lamda: 고유치)
     - A*X = lamda*X, X가 0이 아닌 해를 갖기 위한 lamda 값을 고유치, X를 고유벡터라 함.
     - (A-lamda*I)X = 0, det(A-lamda*I) = 0, (poly: 행렬의 특성 방정식)

카. 놈(norm)
    1. 벡터 norm – norm(x,p): sum(abs(x).^p)^(1/p)와 같음. norm(x,inf) = max(abs(x))
    2. 행렬 norm – norm(A,1): 열의 절대값의 합 중 가장 큰 값, max(sum(abs(A)))와 같음.
                         norm(A,inf): 행의 절대값의 합 중 가장 큰 값, max(sum(abs(A’)))
                         norm(A,’fro’): 모든 요소의 제곱의 합에 대한 제곱근, sqrt(sum(diag(A’*A)))
                         norm(A) 또는 norm(A,2): 행렬 A의 가장 큰 singular value, max(svd(A))

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by downright

2008/01/03 22:39 2008/01/03 22:39

Comments List

  1. 눈e이뿐이lol  2008/02/29 00:19 # M/D Reply Permalink

    답글 보고 블로그에 오게 되었는데 조회수가 굉장하네요. 그리고 수학도 잘하시나봐요. 부럽습니다. +_+ 전공도 저와 비슷한 이과 계열이신듯 하신데 앞으로 좋은 인연 만들어 보아요. ㅎ

    1. downright  2008/02/29 00:36 # M/D Permalink

      굉장하다뇨^^..한가지 팁(?)을 알려드리자면,
      저는 네이버에 등록했구요.(잘 해주는 것 같아요.)
      올블로그넷이랑 블로그코리아도 등록했어요.
      다음은 안했는데 거기에도 등록하면 방문자가 많을 거에요.
      아 그리고 저는 공대생...잘 한다기 보다 피할 수 없는 운명(?)인가봐요.^^

Leave a comment
[로그인][오픈아이디란?]