2012-04-09 36 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,:);