We are trying to model a DC/DC buck converter using matlab's ode23 solver. When we try to run our code the following errors come up:
??? 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);
When we take out the code that modifies the initial condition array the code runs without errors but does not produce the expected result.
This is our code:
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)];
here's the problem:
in the loop, the first iteration:
you call the following
[t,x] = ode23(@event1,[t0 tf],x0);
t0 = 0; and tf = 1;
then further down the loop:
t0 = t(nt); %so t0 = 1;
next for loop iteration:
[t,x] = ode23(@event1,[t0 tf],x0);
in other words:
[t,x] = ode23(@event1, [1 1] ,x0);
solution:
either modify t0 = t(nt);
or update tf with tf = t0 +1;
update:
also, you should correct the following x0 = x(nt,:);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.