Error using odearguments (line 95)
4 次查看(过去 30 天)
显示 更早的评论
>> BATTERcall
Error using odearguments (line 95)
@(T,Y)BATTERY(T,Y,CURRENT,TIME,R1NEW,R2NEW,C1NEW,C2NEW)
returns a vector of length 447379, but
the length of initial conditions vector
is 3. The vector returned by
@(T,Y)BATTERY(T,Y,CURRENT,TIME,R1NEW,R2NEW,C1NEW,C2NEW)
and the initial conditions vector must
have the same number of elements.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed,
solver_name, ode, tspan, y0, options,
varargin);
Error in BATTERcall (line 15)
[T,y] = ode45(@(T,y)
BATTERY(T,y,current,time,R1new,R2new,C1new,C2new),[1
3500], IC);
% main script
y(1)=0.9;y(2)=0;y(3)=0;
IC=[y(1) y(2) y(3)];
load('HPPC_parameters.mat');
R0new = interp1(SOC',R0',x1);
R1new = interp1(SOC',R1',x1);
R2new = interp1(SOC',R2',x1);
C1new = interp1(SOC',C1',x1);
C2new = interp1(SOC',C2',x1);
load('UDDSprofile.mat');
time = UDDSprofile(2:34822,2);
current = UDDSprofile(2:34822,3);
voltage = UDDSprofile(2:34822,4);
[T,y] = ode45(@(T,y) BATTERY(T,y,current,time,R1new,R2new,C1new,C2new),[1 3500], IC);
X1=y(:,1); X2=y(:,2); X3=y(:,3);
% end
% BATTERY file
function dy = BATTERY(T,y,u,time,R1new,R2new,C1new,C2new)
U = interp1(time,u,T);
Q = 1.2*3600;
dy = [-U/(Q);U./C1new - y(2)./(R1new.*C1new);U./C2new - y(3)./(R2new.*C2new)];
end
1 个评论
Walter Roberson
2023-3-4
U = interp1(time,u,T);
The resulting U will not have continuous first derivatives. The mathematics of ode45() requires that the equations have continuous first and second derivatives. If you are going to use interp1() at all you need to use a method that is at least third order, such as
U = interp1(time, u, T, 'spline');
If the values in current reflect impulses of some sort (for example, the system is being stimulated every 5 seconds) then using spline would not give meaningful results, and you would need a different approach that required looping ode45 calls.
回答(1 个)
Torsten
2023-3-4
For the code to work, x1 in the commands
R1new = interp1(SOC',R1',x1);
R2new = interp1(SOC',R2',x1);
C1new = interp1(SOC',C1',x1);
C2new = interp1(SOC',C2',x1);
must be a single value, not a vector of values.
My guess is that this is not the case.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!