How use transfer function (1/s+1) in time domain (in matlab script not simulink) - algebraic equation multiply this transfer function.

I have script (Fuel Cell Model V-I characteristics):
clear all
Eoc=65;
V1=63;
Inom=133.3;
Vnom=45;
Imax=225;
Vmin=37;
Td=3;
numerator=1;
denominator=[Td/3,1];
sys=tf(numerator,denominator)
t=0:0.1:0.1*2250;
NA=((V1-Vnom)*(Imax-1)-(V1-Vmin)*(Inom-1))/(log(Inom)*(Imax-1)-log(Imax)*(Inom-1))
Rom=(V1-Vnom-NA*log(Inom))/(Inom-1)
Io=exp((V1-Eoc+Rom)/NA)
ifc=0.1;
for i=1:2250
ifc=ifc+0.1;
Eact=NA*log(ifc/Io)
E=Eoc-Eact; % in this equation is E=Eoc-Eact*(1/(s*Td/3+1)) how I should multiply this scalar by tf sys?
Vfc=E-Rom*ifc;
VFC(i)=Vfc;
IFC(i)=ifc;
end
plot(IFC,VFC)
How should I change the transfer function to be able to use it in a time domain in this script? I try inverted laplace like this ->
[num,den] = tfdata(sys);
syms s
arrayNum = cell2mat(num);
arrayDen = cell2mat(den);
X2_symbolic = poly2sym(arrayNum,s)/poly2sym(arrayDen,s);
% Valid usage of ilaplace on a symbolic
ss = ilaplace(X2_symbolic);
but what next ss is exp(-t), I won't multiply it E=Eoc-Eact*exp(-t) or like this E=Eoc-exp(Eact) How can I model transmitance 1/s*Td/3+1 to use it in this case?
This equation and model come from "Fuel Cell Stack Example" in simulink "simplified model" -> https://www.mathworks.com/help/sps/powersys/ref/fuelcellstack.html , but I want write own script in matlab not use in simulink -> equation for Eoc, NA, Rom comes from scientific article mentioned in references.

6 Comments

What do you mean by "multiply this scalar with transfer function"?
If you want that, then you can use lsim function. And if you want to do it in every for loop iteration where some of the values change depending on the output of the transfer function, then you can lsim for a single time step.
If you take the inverse laplace, are you planning to apply convolution?
I believe that @Sebastian wants to simulate the fuel cell stack system in the time domain. The block diagram of the fuel cell stack is provided in the Simulink example. The fuel cell stack voltage (E) is described as the difference between the open circuit voltage () and the delayed activation losses . The delay is modeled by a first-order low-pass filter (frequency domain)
,
which can be converted into the time-domain differential equation
,
where η is the activation overpotential given in the Tafel activation equation:
.
Are you trying to model 1/s*Td/3+1 or are you trying to model 1/(s*Td/3+1) ?
@Aquatris I want the calculations to be performed in a loop at each step (in matlab script).
And if you want to do it in every for loop iteration where some of the values change depending on the output of the transfer function, then you can lsim for a single time step.
Can you describe how I can use lsim for a signle time step in this case?
In the time domain, can be written as . You may choose whatever way you want for the discretization of the dy/dt term. The simpliest one would be the 1st order Euler scheme, for which you'll have . Put all known variables to the RHS, in your particular case, this would look like
% inside the loop
Eact = NA*log(ifc/Io);
EactNew = EactOld + 0.1/(Td/3)*(Eact-EactOld); % 0.1 is the time step
E = Eoc - EactNew;
EactOld = EactNew;
Please check the math.
Also note Forward Euler isn't very stable if the time step is too large.
Or, if you know how to write your differential equation for MATLAB's ODE solvers, you can use more robust and accurate solvers. An example: https://www.mathworks.com/help/matlab/math/solve-nonstiff-odes.html

Sign in to comment.

Answers (0)

Products

Release

R2024b

Asked:

on 9 Oct 2024

Edited:

on 11 Oct 2024

Community Treasure Hunt

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

Start Hunting!