14
GS456 Advanced Automatic Control Term Project (2013 Fall Semester) Dynamic Simulation and Control Experiment for Cart-Pendulum System for Cart Pendulum System Dynamic Simulation Modeling and Control Design Control Experiment 1 Control Design Control Simulation and Experiment of a Cart-Pendulum System Mission 1. Control and Estimator Design Derivation of the (coupled nonlinear) dynamic equation of motion. Design of a PID control law with joint angle feedback Design of a PID control law with joint angle feedback Design of a state feedback control law with joint angle feedback Design of a state estimator to reconstruct full-state (by assuming that the cart position and the pendulum angle are measurable) cart position and the pendulum angle are measurable) Mission 2. Dynamic Motion Simulation (Matlab or C++) Numerical integration of the (nonlinear) dynamic equation of motion (apply Runge-Kutta algorithm) Control simulation of Inverted pendulum Data plotting of simulation results Mission 3. Inverted pendulum Control experiment Mission 3. Inverted pendulum Control experiment Understand the H/W and S/W architecture of the Linear-Motor control system Make a control function to implement your controller Perform control gain tuning 2 Perform control gain tuning Data acquisition and plotting of experimental results

Dynamic Simulation and Control Experiment for Cartfor Cart-Pendulum …mercury.kau.ac.kr/sjkwon/Lecture/2013 고등자동제어... ·  · 2013-12-03•Dgn oeis fa state feedback

  • Upload
    ngohanh

  • View
    214

  • Download
    1

Embed Size (px)

Citation preview

GS456 Advanced Automatic Control Term Project(2013 Fall Semester)

Dynamic Simulation and Control Experiment

for Cart-Pendulum Systemfor Cart Pendulum System

Dynamic Simulation

Modeling and Control Design

Control Experiment

1

Control Design

Control Simulation and Experiment of a Cart-Pendulum System

Mission 1. Control and Estimator Design

• Derivation of the (coupled nonlinear) dynamic equation of motion.

• Design of a PID control law with joint angle feedback• Design of a PID control law with joint angle feedback

• Design of a state feedback control law with joint angle feedback

• Design of a state estimator to reconstruct full-state (by assuming that the cart position and the pendulum angle are measurable)cart position and the pendulum angle are measurable)

Mission 2. Dynamic Motion Simulation (Matlab or C++)

• Numerical integration of the (nonlinear) dynamic equation of motion (apply Runge-Kutta algorithm)

• Control simulation of Inverted pendulum

• Data plotting of simulation results

Mission 3. Inverted pendulum Control experimentMission 3. Inverted pendulum Control experiment

• Understand the H/W and S/W architecture of the Linear-Motor control system

• Make a control function to implement your controller

• Perform control gain tuning

2

• Perform control gain tuning

• Data acquisition and plotting of experimental results

Control Simulation and Experiment of a Cart-Pendulum System

[1] (subroutine RK4) Write RK4(Runge-Kutta 4th order) routine for numerical

integration of the dynamic equation of motion

(Input: cart driving force u(t) Output: cart and pendulum motion (x & theta)

→ Two 2nd order equations of motion which are dynamically coupled:

반드시 마찰력을 고려할 것!

(Input: cart driving force u(t) Output: cart and pendulum motion (x & theta)

11 12 11

12 22 22

( , ) 0

( , )

H H g xc

H H g x uc xx

θθθθ

⎧ ⎫⎧ ⎫⎡ ⎤ ⎧ ⎫ ⎧ ⎫+ + =⎨ ⎬ ⎨ ⎬ ⎨ ⎬ ⎨ ⎬⎢ ⎥

⎩ ⎭⎣ ⎦ ⎩ ⎭⎩ ⎭ ⎩ ⎭

⎛ ⎞11 12

12 22

H H

H Hx

θ→

⎧ ⎫ ⎡ ⎤=⎨ ⎬ ⎢⎣ ⎦⎩ ⎭

1

11 1

22 2

( , )0 ( , , , )

( , ) ( , , , , )

g xc f x x

g xu c x f x x u

θθ θ θθ θ θ

⎛ ⎞⎧ ⎫ ⎧ ⎫⎧ ⎫⎧ ⎫+ − =⎜ ⎟⎨ ⎬ ⎨ ⎬ ⎨ ⎬ ⎨ ⎬⎥ ⎜ ⎟⎩ ⎭ ⎩ ⎭⎩ ⎭ ⎩ ⎭⎝ ⎠

Four simultaneous 1st order equations:•

→→

Four simultaneous 1st order equations

RK4 integratio

RK4 algn

orste

itp

hm:

Numerical integration using

= sampling time (ex) 1ms = 0.001 secPl t t

? , ? ,cart pendulumm m l

= = =

:

? m

Plant parameters

kg kg 진자길이(막대)

3

[2] (subroutine JointCtrl) Write joint control function

Joint torque = control input + arbitrary disturbance(your assumption!)

1⎛ ⎞

( ) ( ) ( ) ( )

1( ) ( )p D

p

I

D Iu t k e t k e t k e t dt

K s k k s k e ss

= + +

⎛ ⎞− = + +⎜ ⎟⎝ ⎠

→ ∫

PID control:

( ) ( ) ( ) ( )

( ) ( 1)( ) ( ) ( ) ( 1)

p D I

p D I

e k e ku k k e k k k Te k u k

T

− −⎛ ⎞= + + + −⎜ ⎟⎝

∫discrete-time representation:

p T⎜ ⎟⎝ ⎠

→ Perform your Gain tuning! followi p D Ik k k→ →ng the order:

max0.2

( ) sin( )

, )

, 10 ~ 50 rad / secd

d

d

d t

D

D t

D

u ω

ωω

= =→

− = or

Di

square wave(with magnitude

sturbance input

:

First su

(e

ggestio

frequen

)

cy

x

n

.

max , d

( ) (

)

) ( )

d

t u d t

D

ω

= +

and

Total torque input :

Investigate how the control error is varied according to (

4

max max max

( ) (

( ) 5 ~ 50

) (

[ ]

)

u u t u u

t u d tt

N

τ− ≤ ≤ =

= +−− Total torque input : Consider actuator torque limit ( ex.) :

[3] (subroutine Estimator) Write the state estimator function[4] (subroutine Main)

1) When using MATLAB direct m-file coding is preferred rather than using SIMULINK1) When using MATLAB direct m file coding is preferred rather than using SIMULINK2) When using Microsoft VISUAL C++

Combined State Feedback and Estimator Loop

motor torque limit ( )d t

disturbance Cart-pendulum(nonlinear motion model)

Coupled dynamic

( )d tθref. command

( )x tK(s)

( )e t+ ( )tτ+( )u t dynamic equation of motion

K(s)−( )tθ

( )( )

θ̂State estimator

θ̂

5

State estimatorx̂x̂

PID control loop & State estimation loop

motor torque limit( )d t

disturbance Cart-pendulumMotion model

Coupled dynamic

( )d tθref. command

( )x tK(s)

( )e t+−

( )tτ+( )u t

equation of motion ( )tθ

θ̂ State estimatorθ̂x̂x̂

6

Example of MatLab Code for RK4 Integration (script m-file)

% main m% main.m

% === Example of RK4 Integration algorithm

%------- 2nd order ODE ----------------------% y_ddot + a*y_dot + b*y = 0% with (I C ) y(t=0) = y dot(t=0) =

2

0(0) 3, (0) 0

100 10 / sec

10 2

n n

y ay byy y Spring

kb rad

mω ω

ζ ζ

′′ ′+ + =′= = ←

= = = → =

(I.C.) 3m

Natural freq.( ),

Damping oeff ( )

을 앞으로 당겼다 놓는 경우

고유진동수

감쇠계수% with (I.C.) y(t=0) = , y_dot(t=0) =

clear;

%---------- System Parameters --------------a = 10.; b = 100.;

% (I.C.)

10 2

( , )!

n

n

a ζω ζ

ω ζ

= = → =

Damping coeff.( ),

Try different set of

감쇠계수

% (I.C.)x1(1) = 3.0; x2(1) = 0.0;

h = 0.01; % Integration time interval tf = 3.0; % Final time t = [ 0: h: tf]';

%--- RK4 integration start -----------------------------for i = 1: 1: size(t,1)-1

% Slopes k1, k2, k3, k4k11 = x2(i) ; k12 a*x2(i) b*x1(i);k12 = -a*x2(i) - b*x1(i); k21 = x2(i) + 0.5*k12*h ; k22 = -a*( x2(i) + 0.5*k12*h ) - b*( x1(i) + 0.5*k11*h ); k31 = x2(i) + 0.5*k22*h ; k32 = -a*( x2(i) + 0.5*k22*h ) - b*( x1(i) + 0.5*k21*h ); k41 = x2(i) + k32*h ; k42 = -a*( x2(i) + k32*h ) - b*( x1(i) + k31*h );k42 = -a ( x2(i) + k32 h ) - b ( x1(i) + k31 h );

% Updated value x1(i+1) = x1(i) + (k11 + 2*k21 + 2*k31 + k41)*h/6; x2(i+1) = x2(i) + (k12 + 2*k22 + 2*k32 + k42)*h/6;

end;

7

end;

figure(1); subplot(211); plot(t, x1); xlabel('time(sec)'); ylabel('x1'); title('Position'); grid; subplot(212); plot(t, x2); xlabel('time(sec)'); ylabel('x2'); title('Velocity'); grid;

Example of MatLab Code for RK4 Integration (function m-file):

% === Example of RK4 Integration algorithm% Example of RK4 Integration algorithm% It requires m-files with subfunctions rk4.m & dyn_eqn.m%========================================% 화일명: rk4_main.m or 임의명.m

function rk4_main()

% Subfunction 1

% rk4.m

function x = rk4( x, u, a, b, h )

% Sl k1 k2 k3 k4 2 1 t_ ()

%각 subfunction을 독립적인 m-file로 저장하면 main 함수 이름 생략 가능

%------- 2nd order ODE ----------------------% y_ddot + a*y_dot + b*y = u(t) with (I.C.) y(0), y_dot(0)

% Slopes k1, k2, k3, k4 <-- 2 x 1 vectors

k1 = dyn_eqn( x, u, a, b, h );

k2 = dyn_eqn( x + 0.5*k1*h, u, a, b, h );

k3 = dyn_eqn( x + 0.5*k2*h, u, a, b, h );

k4 = dyn eqn( x + k3*h u a b h );clear;%---------- System Parameters --------------%global a b h;

a = 3.; % c/m

k4 = dyn_eqn( x + k3 h, u, a, b, h );

x = x + h*( k1 + 2*k2 + 2*k3 + k4 )/6;

% Subfunction 2 b = 100.; % k/mh = 0.01; % Integration time interval

% (I.C.)x(1,:) = [3.0 0.0]; %x1(1) = 3.0; x2(1) = 0.0;

% dyn_eqn.m

function f = dyn_eqn( x, u, a, b, h )

f(:,1) = x(:,2);

f( 2) * ( 2) b* ( 1)tf = 3.0; % Final time t = [ 0: h: tf]';

%--- RK4 integration start -----------------------------f i 1 1 i (t 1) 1

f(:,2) = -a*x(:,2) - b*x(:,1) + u;

for i = 1: 1: size(t,1)-1% Input u(i) = 0; x(i+1,:) = rk4( x(i,:), u(i), a, b, h );

end;

8

figure(1); subplot(211); plot(t, x(:,1)); xlabel('time(sec)'); ylabel('x1'); title('Position'); grid; subplot(212); plot(t, x(:,2)); xlabel('time(sec)'); ylabel('x2'); title('Velocity'); grid;

Example of MatLab Code for RK4 Integration (inline function)

% rk4 inline fn m% rk4_inline_fn.mfunction rk4_inline_fn()

%---------- System Parameters --------------a = 3.; % c/mb = 100 ; % k/mb = 100.; % k/mh = 0.01; % Integration time interval

x(1,:) = [3.0 0.0]; %x1(1) = 3.0; x2(1) = 0.0; % (I.C.)

tf = 3 0; t = [ 0: h: tf]';tf 3.0; t [ 0: h: tf] ;

% inline functions for % y_ddot + a*y_dot + b*y = u(t) with (I.C.) y(0), y_dot(0) %-----------------------------------f1 = inline('x2');f1 inline( x2 );f2 = inline('-a*x2 - b*x1 + u', 'x1','x2','u','a','b');

%--- RK4 integration -----------------------------for i = 1: 1: size(t,1)-1

u(i) = 0; % Input ( ) ; p

k11 = f1(x(i,2));k12 = f2(x(i,1), x(i,2), u(i), a, b);k21 = f1(x(i,2)+0.5*k11*h);k22 = f2(x(i,1)+0.5*k11*h, x(i,2)+0.5*k12*h, u(i), a, b);k31 = f1(x(i,2)+0.5*k21*h);k32 = f2(x(i,1)+0.5*k21*h, x(i,2)+0.5*k22*h, u(i), a, b);k41 = f1(x(i,2)+k31*h);k42 = f2(x(i,1)+k31*h, x(i,2)+0.5*k32*h, u(i), a, b);

9

x(i+1,1) = x(i,1) + h*( k11 + 2*k21 + 2*k31 + k41 )/6;x(i+1,2) = x(i,2) + h*( k12 + 2*k22 + 2*k32 + k42 )/6;

end;

Inverted Pendulum on the Moving Cart

Graphic animation using VC++ with OpenGL or Matlab

Experimental setup & Basic C++ code

System Parameters

Mass of cart 2.54 kg

Pendulum mass 0.56 kg

Pendulum length 400 mm

Damping coefficientDamping coefficient of cart

0.1~0.3

Damping coefficient f d l

0.1~0.3

10

of pendulum0.1 0.3

Sampling time 1 ms

Simulation results

1) Confirm the free motion of pendulum and cart (open-loop case)

• With respect to the initial condition changep g

• With respect to the damping coefficient change

2) Closed loop control simulation2) Closed-loop control simulation

• Normal pendulum (with stable eq. point = 0 deg )

• Inverted pendulum (with unstable eq. point = 180 d )deg )

• Investigate how the control performance is varied according to the changes of PID control gain and th it d f di t bthe magnitude of disturbances.

3) State estimator simulation

• Investigate how the estimation performance is varied according to the change of estimator gain.

11

Cart & Inverted Pendulum System Setup (Room 402)

Rotory EncoderCounter

Control program (VC++)

Linear MotorDAC (control command)

Linear Encoder

CounterControl PC

Motor Driver

12

Control Experiment

1) Control error of pendulum

Reference command = 180 deg

Initial posture = 0 deg.

Make a swing motion in open loop mode

2) Standing-on control with Swing motion

Make a swing motion in open-loop mode

When the pendulum arrives around 180 deg

change to closed-loop control mode

iti t l f f i t 180 d

13Control program GUI

position control for ref. input = 180 deg

Reporting and Presentation

Term Project Report

Modeling of Cart-pendulum motion

Basic motion analysis & Stability analysis

Control design & Estimator design

- Transfer function root locus frequency response- Transfer function, root-locus, frequency response

- State feedback & state estimator

Simulation resultsSimulation results

Experiment results

Discussion

Report(PPT file) 제출 & 10 minute Presentation: 12/9(월)

Simulation result Graphic animation is preferred )

Experiment video

Final Exam 12/12(목)

14

Final Exam 12/12(목)

연립 상미방 수치해를 위한 Runge-Kutta 법(RK4 Numerical Integration Method for IVP of Simultaneous(RK4 Numerical Integration Method for IVP of Simultaneous

ODEs)

미분방정식:

• 미지함수와 미지함수의 도함수로 구성되어있는 방정식미지함수와 미지함수의 도함수로 구성되어있는 방정식

상미분방정식(Ordinary differential equation, ODE)

• 함수가 한 개의 독립변수만 포함

편미분방정식(Partial differential equation, PDE)

• 함수가 한 개 이상의 독립변수를 포함

미방에 대한 초기치 문제: IVP(Initial Value Problem)미방에 대한 초기치 문제: IVP(Initial Value Problem)

15

Mass-Damper-Spring System의 예

k

y

( )F t ( )F t

X-방향의 운동방정식 유도

m

k

c

x

mkxcx

mx

x

Mass-damper-spring system:•( ) ( (

( )

: ), ) (2 )

(2 ) 2

F t kx cx mx k c

mx cx kx F t

− − =→ + + =

• →

스프링상수 댐핑 계수

차 미방

차 미방 원연립 1차미방으로

1 2

1 2

2 2 1

,

(2 ) 2

let y y

x y x y F c ky y y

=⎛ ⎞⎜ ⎟= = → ⎜ ⎟= − −⎜ ⎟⎝ ⎠

차 미방 원연립 1차미방으로

2 2 1

1

y y ym m m

⎜ ⎟⎝ ⎠

→ 차미방에대한 수치적분 알 1

2

( ) ( )

( ) ( )

y t x t

y t x t

=⎛ ⎞→ ⎜ ⎟=⎝ ⎠

고리즘 적용 를 구함

16

Pendulum의 예

상미분방정식(ODE)상미분방정식(ODE)1) 선형상미방(Linear ODE): 선형함수만을 포함하는 미분방정식

2) 비선형상미방(Nonlinear ODE): 비선형함수가 포함된 미분방정식

Pendulum(진자) 비선형 상미방 특성

x T (tension)

2

θl m mxm= mlθ

2mlθ

m=

Mass-damper-spring system:•

my mg my let y yθ θ• 수치해 구하기:

2

2

sin cos sin

cos sin cos Tangential

x l x l l

y l y l l

θ θ θ θ θ

θ θ θ θ θ

= → = −

= → = − −•

진자의 방향의 운동방정식

1 2

1 2

2 1

,let y yy y

gy y

l

θ θ= ==⎛ ⎞

⎜ ⎟→ = −⎜ ⎟⎝ ⎠

sin sin 0 (

sin ,cos 1)

Tangential

)

for small

gmg ml

lθ θ θ θ

θ θ θ θ

− = → + =

• → ≈ ≈

진자의 방향의 운동방정식

비선형상미방

선형화된운동방정식(

( )1

1

( ) ( )

l

y t tθ

⎝ ⎠

=⎛ ⎞⎜ ⎟

차미방에 대한

수치적분 알고리즘

17

θ sin 0 0 ( )g g

l lθ θ θ+ = → + = 선형상미방

1

2

( ) ( )

( ) ( )

y

y t tθ⎛ ⎞

→ ⎜ ⎟=⎝ ⎠

상미방에 대한 수치적분

( , ) ( )

1

data dy

f x y y g xdx

= → =

차 상미방

에해당하는 수치해(x값에대한 y의 )를 찾음.

1

1

i i

dx

y y hφ+

= +

차 상미방에대한 수치적분 알고리즘의일반적인형태

1) ) ( ) (at (at

i ix x x x h

φ+⇔ = = = + ×

• →새로운 기울기

기울

값 이전값 구간간격

각 알고리즘의차이 를 결정하는 방법의기 차이

18

Euler Method

( , ) 1 dy

y f x ydx

hφ φ

′• = =차 상미방:

를 시작점에서의도함수로 사용기울기1

1 1

( , )

( )

i i

i i i

i i i i

y y hy f x y

y y y ydyf

φ φφ

+

+ +

= + →′= =

− −⎛ ⎞ ′⎜ ⎟

를 시작점에서의도함수로 사용

기울기

1 1

1

1

( , )

( , )

: Euler method

i i i ii i i

i i i

i i i i

y y y ydyy f x y

dx x x h

y y f x y h

+ +

+

+

⎛ ⎞ ′≈ = = =⎜ ⎟ −⎝ ⎠

→ = +

1iy +

iy( , )i ih f x y h yφ = = Δ

19

<Euler 법에서의 오차의 누적>

개선된 Euler법 (RK2법)

1[1] ( , )( , )

:

i i i i

i i i

y y f x y hy f x yφ+ = +′→ = =

Euler 법:

기울기구간 시작점에서의기울기

1

:

[2]

i i iy y y h+ ′= +

Heun

구간 시작점에서의기울기

법:

1

10

11( , ) ( , )

2 2i

i i i

i i ii ii

y y yf x y f x yy y

yφ +

+

+++′ ′+′→ = = =

:

기울기

구간 시작과 끝 기울기의평균

(f+

[3] 중앙점법(Midpoint method):

)h1 ( ii i f xy y+ = +

1/ 2 1/ 2 1/

1/ 2 / 2

2

1

)

, )

( ,i i

i

i

h

y f x y

y

φ+

+ +

+

+′→ = =

:

기울기

구간 중앙점에서의기울기

1/ 2

1/ 2( , )

2

i

i i i i

x

hy y f x y

+

+= +

⎛ ⎞⎜ ⎟⎜ ⎟⎝ ⎠

Midpoint:

20

개선된 Euler법 (RK2법)

<Euler법과 Heun법의 성능 비교>

21

Runge-Kutta법

d

1

( , )

( , , )

1

i i i i

dyf x y

dxy y x y h hφ+

• =

= +

차 상미방 에대한 수치해

( , , ) : h)

Incremental function ( )i ix y hφ→ 적분구간( 에서의대표적인기울기

증분함수

증분함수의일반적인형태

1 1 2 2( , , )

i i n nx y h a k a k a kφ = + +•

+

증분함수의일반적인형태

1 1~ ~ n na a k k 은 상수, 은 기울기값들1 1

1

2 1 11 1

3 2 21 1 22 2

( , )( , )( , )

n n

i i

i i

i i

k f x yk f x p h y q k hk f x p h y q k h q k h

=⎛ ⎞⎜ ⎟= + +⎜ ⎟= + + +⎜ ⎟3 2 21 1 22 2

1 1,1 1 1,2 2 1, 1 1

( , )

( , )

RK

i i

n i n i n n n n n

k f x p h y q k h q k h

k f x p h y q k h q k h q k h− − − − − −

+ + +⎜ ⎟⎜ ⎟⎜ ⎟= + + + + +⎝ ⎠

법의분류

1 1) : 1

RK n =

• 법의분류

23

RK (RK1) Euler 2) : 2 RK (RK2) Heun , Midpoint

3) 3 RK (RK3)n

→= →

차 법 법

차 법 법 법

차 법

22

34

3) : 3 RK (RK3) 4) : 4 RK (RK4)

nn==

차 법

차 법

3차 Runge-Kutta법

( )1 1 32

1 4 1

14

6[RK3] i iy y k k k h+ = + + +

1 2 3

1

1 4 1, ,

6 6 6

( , )1 1

, ,

i i

k k k

k f x y

←=⎛ ⎞⎜ ⎟

기울기 에 각각 가중치

구간 시작점의기울기

2 1

213

1 1( , )

2 22( , )

i

i i

i

k f x h y k h

k f x h y k h k h

⎜ ⎟= + +⎜ ⎟

⎜⎜ = + − +⎝ ⎠

구간 중앙점의기울기

구간 끝점의기울기

⎟⎟

⎝ ⎠

23

4차 Runge-Kutta법 : 가장 보편적인 방법

( )1 2 3 4

1

1 1 2 3 4

1 2 2 1, , ,

6 6 6 6

( , )6

12 2i i

i i

k k k k

k f x y

y y k k k k h+ ←

←=⎛⎜

= + ++ +

[RK4] , , , 기울기 에 각각 가중치

구간 시작점의기울기 ⎞⎟

1

2 1

( , )1 1

( , )2 21 1

( )

i i

i i

f y

k f x h y k h

k f h k h

←⎜

= + +⎜⎜⎜ + +

구간 중앙점의기울기

구간 중앙점의기울기

⎟⎟⎟⎟

3 2

4 3

( , )2 2

( , )

i i

i i

k f x h y k h

k f x h y k h

⎜ = + +⎜⎜⎝ = + +

구간 중앙점의기울기

구간 끝점의기울기

⎟⎟⎟⎠

24

연립미분방정식

n차 미방 n개의 1차 연립미방으로 변환

n차 미방 또는 n개의 1차 연립미방의 해를 구하기 위해서는

개의 조건이 필요n개의 조건이 필요

d( , ) 1 :

1

dyy f x y

dx′• = =차 상미방

원연립 차 상미방

11 1 2( , , , , )

n 1

n

dyf x y y y

dx

•⎧ ⎫=⎪ ⎪⎪ ⎪

원연립 차 상미방

22 1 2

1

( , , , , ) : ~

nn

dyf x y y y y ydx

⎪ ⎪⎪ ⎪=⎨ ⎬⎪ ⎪⎪ ⎪

각각의초기치 n개필요

1 2( , , , , )nn n

dyf x y y y

dx

⎪ ⎪⎪ = ⎪⎩ ⎭

25

n차 미분방정식 n원 1차 연립방정식

( ) ( 1)

( 1)

( , , , , , )

, ,( , ,

n :

)

nn n

n

n

d yy f x y y y y

dxy y y y

′ ′′• = =

′ ′′→

차 상미방

에대한 초기치 n개필요

( )( 1)1 2

1

3, , ,, Let Then, n

nny y y y y y y y

dyf

−′ ′′= = = =

차 상미방

⎧ ⎫11 1 2

22 32

yy f y

dxdy

y f ydx

′ = = =

′ = = =→ 1

⎧ ⎫⎪ ⎪⎪ ⎪⎪ ⎪⎨ ⎬⎪ ⎪

:n원연립 차 상미방으로 변환

dx

1 2( , , , , )

n

n n n

dyy f f x y y y

dx

⎨ ⎬⎪ ⎪⎪ ⎪

′⎪ = = = ⎪⎩ ⎭

0

( , , )(0)

(

:

) 2

2 y f x y yy y

y y

′′ ′==⎛ ⎞′→ ⎜ ⎟

• 차 상미방의 경우

에대한 초기치 개 필요0

1 1 2

2 2 1 2

1

2

( ,(0)

( , ,

) 2

Let y y

y yy y

y f yy f f x y yy y

→ ⎜ ⎟′ ′=⎝ ⎠′ = =⎛ ⎞→⎜ ⎟ ′ = =⎝

=′ = ⎠

에대한 초기치 개 필요

1 0

2 0

(0)) (0)

with y yy y

=⎛ ⎞⎧ ⎫⎨ ⎬ ⎜ ⎟′=⎩ ⎭ ⎝ ⎠

26

2 2 1 22 ( , ,y f f y yy y⎝ ⎠ 2 0) ( )y y⎩ ⎭ ⎝ ⎠

2차 미분방정식에 대한 RK4 알고리즘

20

20

(0)( , , )

(0)

d

d y y yy f x y y

y ydx

=⎛ ⎞′′ ′= = ⎜ ⎟′ ′=⎝ ⎠⎧ ⎫

with

1

2 1 1 21 01

22 2 01 2 2 1 2

( , , ) (0)

(0)( , , ) ( , , )

dyy f x y y y yy y dx

dyy y y yf x y y f x y y

dx

= = ==⇒′ ′= =

= =

⎧ ⎫⎪ ⎪ ⎛ ⎞⎛ ⎞⎜ ⎟ ⎜ ⎟⎨ ⎬

⎝ ⎠ ⎝ ⎠⎪ ⎪⎩ ⎭

Let with

( ) ( )1,1 2,1 3,1 4,1 1 1,1 ,1 12 21

:6i iy f y y hk k k k+′ = = + + + +

• For

RK4 수치해:

dx⎩ ⎭

( ) ( )1 1

1,2 2,2 3,2 4,2

,2

2 2 1,2 ,2

1,1 1 ,1( , )

61

:6

,

2 2i i

i i i y f

y f y y hk k k k

yfk yx

+

′← =

+ + +′ = = +

⎛ ⎞⎜

=

⎟for

For

RK4

수치해:

2 21 ,2 2 21, ,( , , )i i i y fk yf yx ′← ==⎜⎝ ⎠

⎟for

1 1

2 2

2,1 1 ,1 1,1

,1 1,1

,2 1,2

2,2 2 ,2 1,2

0.5( , 0.( 0.5 , )

0.50.5 ,0.5 , 5 )

i

i

i

i i

i y f

y f

y k hk f y k hy k h

x hxk f y k hh

′← =′ =←

+= += +

++⎛ ⎞

⎜ ⎟+⎝ ⎠f

f

o

or

r

1 1

, ,

3,1

, , ,

,2 2,2

3,

1 ,1 2,1

2

( , 0.50. , ).55 0i i i y fk f y k y k hhxk

h ′ =←+=⎝

+ +⎠

for

22,1 2,1

4 1 1 1 3 1

2 ,2 2,2

2 3 2

0.5 ,

( ,

( 0.5 )0.

)

5 ,

,ii i

ii i

y f

y f

f y k h

y k h

y k h

k

x

f y

h

x h hk ′←

=

′ =⎛ ⎞⎜ ⎟+⎝ ⎠

+⎛ ⎞

= ++

+= + for

for

27

2 2

1 14,1 1 ,1 3,1

,

,2 3,2

4,2 1 3,2 ,2 3,21

( , ), )

,,(

i

i i

i i

i y f

y fy k hk f y k hk f yx h h

xk

y k hh←

′← =

+⎛ ⎞⎜ ⎟+⎝ ⎠

+= +

++

for

for

모듈화된 RK4 코드 작성

(xout 구간 내에서h 간격으로 적분)

(xout 간격으로(RK4 method에 의해h 구간 끝의 적분값 계산)

(xout 간격으로적분값 저장)

xout 간격으로 출력

(미분방정식 계산)

xout 간격으로 출력

28

(미분방정식 계산)