11-3 ODE ?令?選??

Ҧ ODE OiHĥ|ӿJܼơANnL{Ψ쪺Uؿﶵ]Options^A ODE O榡G

[t, y] = solver('odeFile', [t0, tn], y0, options);

䤤 options O odeset OӱcܼơAcܼƧY]tFnL{Ψ쪺UؿﶵAodeset @榡pUG

options = odeset('name1', value1, 'name2', value2, K)

ɲͪcܼ optionsA name1 Ȭ value1A name2 Ȭ value2A̦CQ]wAȧYw]ȡC

ڭ̤]iHuܤ@Ӳ{s options cܼƤAY쪺ȡA榡pUG

newOptions = odeset(options, 'name', value);

YnŪXY쪺ȡAi odegetA榡pUG

value = odeget(otpions, 'name');

䤤 name W١Avalue YȡC

ϥ odeset OɡAYLJܼơAh odeset |ܩҦW٤ȡAåHjANw]ȡAҦpG

Example 1: 11-`L{/odeset01.modeset AbsTol: [ positive scalar or vector {1e-6} ] RelTol: [ positive scalar {1e-3} ] NormControl: [ on | {off} ] NonNegative: [ vector of integers ] OutputFcn: [ function_handle ] OutputSel: [ vector of integers ] Refine: [ positive integer ] Stats: [ on | {off} ] InitialStep: [ positive scalar ] MaxStep: [ positive scalar ] BDF: [ on | {off} ] MaxOrder: [ 1 | 2 | 3 | 4 | {5} ] Jacobian: [ matrix | function_handle ] JPattern: [ sparse matrix ] Vectorized: [ on | {off} ] Mass: [ matrix | function_handle ] MStateDependence: [ none | {weak} | strong ] MvPattern: [ sparse matrix ] MassSingular: [ yes | no | {maybe} ] InitialSlope: [ vector ] Events: [ function_handle ]

oW٤άAiUG

OWƫAw]
~teԫפRelTol¶q$10^{-3}$۹~teԫ
AbsTo1¶qΦVq$10^{-6}$~teԫ
nXOutPutFcnr'odeplot'X禡]Y ODE OLXܼơAhbƭȿn槹AMATLAB |IsX禡^
OutputSelަVqODE OXܼƪޭȡAHMwǿXܼƤNQeX禡
Refine14 (for ode45)Refine = 2 iͨ⭿ƶqXIARefine = 3 iͤTƶqXIA̦C
Statson offoffStats = 'on' ͭpL{UزέpơC
Jacobian x}Jconstanton offoffpG Jacobian x}`ơAh Jconstant = 'on'
Jacobianon offoffYF(t, y, 'Jacobian') Ǧ^ $\partial F/\partial y$Ah Jacobian = 'on'
Jpatternon offoffY F([ ], [ ], 'JPattern') Ǧ^ $\partial F/\partial y$AB $\partial F/\partial y$ O}x}Ah Jpattem = 'on'
Vectorizedon offoffY F(t, [y1, y2K..]) Ǧ^ [F(t,y1), F(t,y2)K..]Ah Vectorized = 'on'
nB]Step Sizes^Max Step¶q ODE OnB W
Initial Step¶q _lBij
qx}MassnoneAMAM(t)A M(t, y)none ODE O׬O_|Ǧ^qx}
MassSingularyesAno maybemaybeqx}O_ Singular
ƥoͮɶEventson offoffY ODE ɮרöǦ^ƥ禡άTAh Events = 'on'
Ode15s MaxOrder1, 2, 3, 4 55nΨ쪺̰
BDFon offoffYϥ BDF]Backward Differentiation Formula^h BDF = 'on'

HUXӱ`Ψ쪺Ӷi满C

f bn~teԫפ譱AC@nҲͪ~t e(i)AUC{G

$$ |e(i)| \leq max(RelTol*|y(i)|, AbsTol(i)) $$

䤤 i N i ӪAܼơA]Aڭ̥iC RelTol AbsTol ӨDoTnGCҦpG

Example 2: 11-`L{/odeRelTol01.msubplot(2,1,1); ode45('vdp1', [0 25], [3 3]'); title('RelTol=0.01'); options = odeset('RelTol', 0.00001); subplot(2,1,2); ode45('vdp1', [0 25], [3 3]', options); title('RelTol=0.0001');

bWzdҤAĤ@ӹϩҨϥΪ۹~tȬO0.01]w]ȡ^AĤGӹϩҨϥΪ۹~tȬO0.00001A]ڭ̱oӱKIAҪ᪺pɶ]|C

bnXBz譱Aڭ̥iHΤ@ OutputFcnAϱo ODE OSXܼƮɡAX禡 OutputFcn |Q MATLAB IsCOutputFcn w]ȬOodeplotA\ରeXҦAܼơA䥦iΪ禡٦G

H Lorenz P{]Lorenz Chaotic Equation^ҡA ODE ɮפeiܦpUG

11-`L{/lorenzOde.mfunction dy = lorenzOde(t, y) % LORENZODE: ODE file for Lorenz chaotic equation SIGMA = 10.; RHO = 28; BETA = 8./3.; A = [ -BETA 0 y(2) 0 -SIGMA SIGMA -y(2) RHO -1 ]; dy = A*y;

ϥ ode45 WzLorenz P{iƭȿnAidҡG

Example 3: 11-`L{/odeLorenz01.mode45('lorenzOde', [0 10], [20 5 -5]');

Ъ`NbWCϤA@TuANTӪAܼHɶܤƪϧΡCYneTתŶۦϧΡAiϥΤUCdҡG

Example 4: 11-`L{/odeLorenz02.moptions = odeset('OutputFcn', 'odephas3'); % ϥ odephas3 iø ode45('lorenzOde', [0 10], [20 5 -5]', options);

WzϧΤuX{@uAuNHTӪAܼƬyСBHɶѼƪ@TתŶuC

Hint
Yn[ Lorenz P{HɶܪʵeAib MATLAB OUJlorenz OYiCD`Aȱo@ݡI

@ӨA]ڭ̪ OutputFcn ]"myFunc"G

options = odeset('OutputFcn', 'myFunc')

hbӿnL{AmyFunc QIsppUG

  1. n}lɡAODE O|Is myFunc(tspan, y0, 'init') H myFunc iUتlưʧ@C
  2. bCӿnBJAODE ON|Is status=myFunc(t, y)AY status=1AhnC
  3. bnɡAODE O|Is myFunc([], [], 'done')AH myFunc i榬ʧ@C
]AYڭ̭nbnL{ͰʵeANiHھڤWzhӳ]p myFunc.mC

OutputSel iwnǰe OutputFcn AܼƤCҦpAYunǰeĤ@βĤT Lorenz P{AʼƦ odeplotAiJpUG

Example 5: 11-`L{/odeOutputSelect01.moptions = odeset('OutputSel', [1,3]); % ueXĤ@MĤTӪAܼ ode45('lorenzOde', [0 10], [20 5 -5]', options);

bWϤAڭ̥ueXFĤ@MĤTӪAܼơC

Refine iHϥΤkӼW[XAܼƪKסAHoƪXuCbUҤAڭ̧Q Refine Ө ode23 XIӼƼWTG

Example 6: 11-`L{/odeRefine01.msubplot(2,1,1); ode23('vdp1', [0 25], [3 3]'); subplot(2,1,2); options = odeset('Refine', 3); ode23('vdp1', [0 25], [3 3]', options);

Stat=on ɡAODE O|b槹ܭpL{UزέpƦrAҦpG

Example 7: 11-`L{/odeShowStats01.m[t, y] = ode45('vdp1', [0 25], [3 3]', odeset('Stat', 'on'));71 successful steps 10 failed attempts 487 function evaluations

ۦPέpƦrA]i ODE OĤTӿXܼƶǦ^AҦpG

Example 8: 11-`L{/odeShowStats02.m[t, y, s] = ode45('vdp1', [0 25], [3 3]'); ss = 71 10 487 0 0 0

MaxStep InitialStep iΨӽվ̤jnBΰ_lnBC@ӨAzhվoӼƭȡA] ODE ON㦳B۰ʽվA\CSOȱo`NOG

䥦]֥ΨAAحzA쪺Ū̡Ai½\ MATLAB ODE UC


MATLAB{]pGig