How can I add values of an array as an input into the ode45 function ?
    10 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Ece Kurt
 el 13 de Nov. de 2019
  
    
    
    
    
    Respondida: Ece Kurt
 el 13 de Nov. de 2019
            
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?
0 comentarios
Respuesta aceptada
  James Tursa
      
      
 el 13 de Nov. de 2019
        
      Editada: James Tursa
      
      
 el 13 de Nov. de 2019
  
      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 comentarios
  Stephen23
      
      
 el 13 de Nov. de 2019
				Ece Kurt's "Answer" moved here:
 this is the DE. dydt is represents the
       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'.
  James Tursa
      
      
 el 13 de Nov. de 2019
				
      Editada: James Tursa
      
      
 el 13 de Nov. de 2019
  
			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.
Más respuestas (1)
Ver también
Categorías
				Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


