MATLAB Answers

Ece Kurt

How can I add values of an array as an input into the ode45 function ?

Ece Kurt
さんによって質問されました 2019 年 11 月 13 日 7:45
最新アクティビティ Ece Kurt
さんによって 回答されました 2019 年 11 月 13 日 9:35
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,
tspan=[1 1370];
function dydt=soc(t,y,Q,I)
dydt= (-I(t)/(3600*Q)); %Here I(t), is an array form. 1370x1 double
%----------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)
Plese help me. Why I always get this error? Is there any other way to implement an array as a input to function?

  0 件のコメント

サインイン to comment.

2 件の回答

James Tursa
Answer by James Tursa
on 13 Nov 2019 at 7:55
Edited by James Tursa
on 13 Nov 2019 at 7:58
 Accepted Answer

What is the size of I? What is the DE you are solving? Maybe just dropping the (t) will work:
dydt= (-I/(3600*Q));
Or maybe you need to interpolate I based on the value of t. It is hard to know how to advise without knowing what DE you are solving and exactly what I is.

  2 件のコメント

Ece Kurt's "Answer" moved here:
this is the DE. dydt is represents the .
I(t) current and I have just values of it. It's not an equation form. Its an array. I have the data of the input current of the battery. So, I just load it to the script and now I want to use it for SOC calculation. Size of the current data is 1370x1 double. Thanks
dydt= (-I/(3600*Q));
Undefined unary operator '-' for input arguments of type 'function_handle'.
If I is an array of values at specific times, then you will need to interpolate I inside your derivative function to get the value of I at the specific time t that the ode45 solver wants. I must cover the entire range of time of the integration. What are the time values corresponding to I? You will need that to do the interpolation.
Another simpler option may be to just use cumtrapz( ) on your-I/(3600*Q) array to get your SOC values. You will need the time points of I to do this correctly also.

サインイン to comment.

Ece Kurt
Answer by Ece Kurt
on 13 Nov 2019 at 9:35

Okay! I think it works. Thank you all!!
load('Current.mat'); %1370x1 double
tspan=[1 1370];
function dydt=soc(t,y,Q,I)
dydt= (I(t)/(-3600*Q));

  0 件のコメント

サインイン to comment.

Translated by