2012-04-09 35 views
1

我們試圖用matlab的ode23求解器對DC/DC降壓轉換器建模。當我們試圖運行我們的代碼下面的錯誤上來:matlab ode23求解器錯誤未知

??? Error using ==> odearguments at 91 
The last entry in tspan must be different 
from the first entry. 

Error in ==> ode23 at 171 
[neq, tspan, ntspan, next, t0, tfinal, 
tdir, y0, f0, odeArgs, odeFcn, ... 

Error in ==> buck2 at 13 
     [t,x] = ode23(@event1,[t0 tf],x0); 

當我們採取的是修改了初始條件數組的代碼運行沒有錯誤,但不會產生預期的結果的代碼。

這是我們的代碼:

function buck2 
close all 
clear all 
clc 

t0 = 0; 
tf = 1; 
x0 = [0 0]; % Initial conditions 

for i = 1:10 
    if (1 <= i <= 4), 
     [t,x] = ode23(@event1,[t0 tf],x0); 
     nt = length(t);   
    else 
     [t,x] = ode23(@event2,[t0 tf],x0); 
     nt = length(t); 
    end 
    t0 = t(nt); 
    x0 = x(nt); 
end 

plot(t,x) 

function xdot = event1(t,x) 
L = (12.12e-6); 
C = (19.5e-6); 
RC = (2.5*19.5e-6); 
xdot = [(24/L) - (x(2)/L); (x(1)/C) - (x(2)/RC)]; 

function xdot = event2(t,x) 
L = (12.12e-6); 
C = (19.5e-6); 
RC = (2.5*19.5e-6); 
xdot = [-(x(2)/L); (x(1)/C) - (x(2)/RC)]; 

回答

0

這裏的問題:

在循環

,第一次迭代:

您撥打以下

[t,x] = ode23(@event1,[t0 tf],x0); 

T0 = 0 ;和tf = 1;

再往循環:

t0 = t(nt); %so t0 = 1; 
下一個for循環迭代

[t,x] = ode23(@event1,[t0 tf],x0); 
換句話說

[T,X] = ODE23(@事件1,[11],x0);

解決方案:

要麼修改t0 = t(nt);或更新TF與tf = t0 +1;

更新:

也,你應該糾正以下x0 = x(nt,:);