How can I add values of an array as an input into the ode45 function ?
Afficher commentaires plus anciens

This is my current profile and I want to calculate the SOC of the battery based on this current profile. So, I have the array of the current values of each time.
I wrote a function like,
load('Current.mat');
I=Current.mat;
Q=2.4;
tspan=[1 1370];
y0=[0];
[t,y]=ode45(@soc,tspan,[y0],[],Q,I);
function dydt=soc(t,y,Q,I)
dydt= (-I(t)/(3600*Q)); %Here I(t), is an array form. 1370x1 double
end
%----------but I get this error whenever I run the code.
Array indices must be positive integers or logical values.
Error in Ode_example>soc (line 46)
dydt= (-I(t)/(3600*Q));
Error in odefcncleanup>@(t,y)oldFcn(t,y,inputArgs{:}) (line 11)
newFcn = @(t,y) oldFcn(t,y,inputArgs{:});
Error in ode45 (line 299)
f2 = odeFcn_main(t2, y2);
Error in Ode_example (line 32)
[t,y]=ode45(@soc,tspan,[y0],[],Q,I);
Plese help me. Why I always get this error? Is there any other way to implement an array as a input to function?
Réponse acceptée
Plus de réponses (1)
Ece Kurt
le 13 Nov 2019
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!