matlab ode23解算器错误未知
我们正在尝试使用matlab的ode23解算器对DC/DC降压变换器进行建模。当我们尝试运行代码时,会出现以下错误:matlab ode23解算器错误未知,matlab,Matlab,我们正在尝试使用matlab的ode23解算器对DC/DC降压变换器进行建模。当我们尝试运行代码时,会出现以下错误: ??? 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, od
??? 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)];
函数buck2
全部关闭
清除所有
clc
t0=0;
tf=1;
x0=[0];%初始条件
对于i=1:10
如果(1问题出在这里:
在循环中,第一次迭代:
[t,x] = ode23(@event1,[t0 tf],x0);
你称之为
[t,x] = ode23(@event1,[t0 tf],x0);
t0=0,tf=1
然后再往下循环:
t0 = t(nt); %so t0 = 1;
循环迭代的下一步:
[t,x] = ode23(@event1,[t0 tf],x0);
换言之:
[t,x]=ode23(@event1,[11],x0)
解决方案:
修改t0=t(nt);
或使用tf=t0+1;
更新:
另外,您应该更正以下x0=x(nt,:);