How can I create the MATLAB code for the same result when the result is implemented in Simulink about State-Space equation solving?
1 view (last 30 days)
Show older comments
I have 1) Input : timeseries Data, 2) State-Space equation parameter(A,B,C,D).
t_P = (0:0.01:10); % Time
P = 95 + 10*sin(2*pi*75/60*t) + 9*sin(4*pi*75/60*t); % time-varying data
y = [t_P;P];
ys = timeseries(y(2:end,:), y(1,:));
save('inputsigPressure', 'ys','-v7.3'); % Making timeseries data for Simulink
%% State-Space equation Parameter(A,B,C,D)
R = 0.79;
C = 1.22;
r = 0.056;
AA = -(1/R + 1/r)/C;
BB = 1/(r*C);
CC = -1/r;
DD = 1/r;
So, when I solved the state-space equation with Simulink, I was able to get the result.
(Sample Time in From File Block : 0.01 / Initial Condition in Space-State Block : 0)
But I need to create this process(solving State-Space equation in Simulink) to Matlab code.
ic = 0;
tspan = [0 10];
[t,x] = ode45(@(t,x) odefun(t, x, t_P, P), tspan, ic); % solve s
y = CC*x + DD*P'; % result y => error(The array size of x and P is not match.)
function dxdt = odefun(t, x, t_P, P)
R = 0.79;
C = 1.22;
r = 0.056;
AA = -(1/R + 1/r)/C;
BB = 1/(r*C);
P = interp1(t_P,P,t);
dxdt = AA*x + BB*P; % Space-state equation
end
I know that Simulink use ode45 function in order to solving State-Space equation.
I think x can be solved by ode45 function and y can be obtained by the equation(y = C*x+D*u).
But The array size of x and P is not match.
For result, How can I solve this probrem?
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!