how do i resolve this ode45 problem
显示 更早的评论
I need to simulate a power multilevel inverter. For that i generate a vector (1x1000double) called Vo, represented by the blue signal:

The simulation is simple, it requires solving the following ecuation:
; with R=30 and L=0.0133 for t=[0 ,1/50].when i try to solved it with "Vo" as a vector it returns an error, but then i try to transform this "Vo" vector into a function that fits in the time t=[0 1/50], with the following:
fo=50; mf=20;
t=linspace(0,1/fo,mf*fo);
Vof=@(t) Vo(1+ceil(t.*fo.*(length(t)-1));
the issue is that when i try to simulate the circuit the returned output it's a vector full of 0...
R=30; L=0.0133;
dio=@(t,io) (Vof(t)./L)-((R*io)/L);
tspan=[0 1/fo];
io0=0;
[tt,io]=ode45(dio,tspan,io0);
plot(tt,io),hold on
plot(t,Vof(t))

how should i resolve this problem? any ideas?
PS: sorry for such weak explanation... first time asking.
回答(1 个)
Your expression contains unbalances parentheses:
Vof=@(t) Vo(1+ceil(t.*fo.*(length(t)-1));
4 opening ( but only 3 closing ).
If this is fixed, the next error concerns "Vo". What is this?
Finally remember, that ODE45 is designed to integrate smoth functions. Your function does not look like it is differentiable. Then the step size controller of ODE45 can drive mad and the results can be dominated by rounding errors.
The integral of a piecewise constant function can be calculated by a sum more accurately and efficiently.
Prefer simple code. Compare these equivalent definitions:
dio = @(t,io) (Vof(t)./L)-((R*io)/L);
dio = @(t,io) Vof(t) / L - R * io / L;
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!