I am trying to use the nonlinear greybox model to estimate the parameter R0 in my state space model (attached). However, I have an extra variable Voc which is a column vector and varies depending on the time. How can I write this in my function under modelfile name (ie nlm = idnlgrey('batteryeq',order,parameters,initial_states,Ts)? I get an error saying "Subscript indices must either be real positive integers or logicals." with my current code:
function [dx,y] = batteryeq(t,x,u,T1,T2,C1,C2,R0,OCV,varargin)
% Output equation.
y = [-x(1);-x(2)]-R0*u+OCV(t); % output equation
% State equations.
dx = [-1/T1+(1/C1)*u;-1/T2+(1/C2)*u];
end
Thank you.

 Réponse acceptée

Prashant Arora
Prashant Arora le 17 Juil 2017
Hi Imisi,
If you already know the dependence of OCV on time, you can definitely pass it as a parameter. However, as time is a floating value, you'll need to "index" into OCV with the corresponding index of time, rather than the actual decimal value of time. (OCV(t) in your code)
For example, let's say OCV = 100X1 where OCV defines the Open-circuit voltage for time = 1 to 100 seconds. Given that you know the value of current time in the function as variable, t, you can compute the OCV at the time using linear interpolation:
interp1(1:100,OCV,t);

3 commentaires

Imisi Jo
Imisi Jo le 19 Juil 2017
Hello,
Thank you! Yes I realised my mistake with the 't' variable, so I did exactly what you suggested. However, the problem I am now having is due to the time being non uniform (but is the same array size as OCV), I had to pass the time array along with the OCV to give me interp1(time_OCV,OCV,t). When running nlgreyest, I just get an error which says 'The specified model parameters or states are infeasible for simulation.', even though when I use the state space block in simiulink and simulate the model, I am able to get a result. Any suggestions on how I can make the model feasible? (I know what the states should be too).
This is probably happening because the variable "t" spans outside the domain of "time_OCV", which results in interp1 to produce NaNs.
You can specify interp1 to use extrapolation outside the domain using
interp1(time_OCV,OCV,t,'linear','extrap')
Imisi Jo
Imisi Jo le 20 Juil 2017
Ok I will try that, thank you! I assume there is no way for me to limit the time duration of 't'?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by