Converting differential equations to State-Space/Transfer Function representation

I'm trying to solve some Control Systems questions, but having trouble with a few of them:
Basically, the question asks for the state-space representation of each system.
I used odeToVectorField for systems a and b:
syms y(t) u(t) t
yd = diff(y);
ydd = diff(y, 2);
yddd = diff(y, 3);
EQD = ydd + 3*yd + y == u
EQD(t) = 
[SS, Sbs] = odeToVectorField(EQD)
SS = 
Sbs = 
EQD2 = yddd + 5*ydd + 8*yd + 12*y == u
EQD2(t) = 
[SS2, Sbs2] = odeToVectorField(EQD2)
SS2 = 
Sbs2 = 
from which I can get the state-space representation.
But when I get to the other systems (for example, system f), it gets trickier, and most of the systems can't even be solved using odeToVectorField.
syms y(t) u(t) t
yd = diff(y);
ydd = diff(y, 2);
yddd = diff(y, 3);
yi = int(y, 0, t);
ud = diff(u);
EQD = ydd + 2*yd + y + yi == ud + 5*u
EQD(t) = 
[SS, Sbs] = odeToVectorField(EQD)
Error using mupadengine/feval_internal
Number of indeterminates exceeds the number of ODEs.

Error in odeToVectorField>mupadOdeToVectorField (line 171)
T = feval_internal(symengine,'symobj::odeToVectorField',sys,x,stringInput);

Error in odeToVectorField (line 119)
sol = mupadOdeToVectorField(varargin);
Is there an easier way to get the state-space representation (or transfer function) directly from the differential equations? And how can I do the same for the more complex differential equations (like f and g, for example)?
Thank you

 Réponse acceptée

There really is no need to use the symbolic stuff (though you can if you really want, at least for part of the problem). Suppose Z(s) is the Laplace transform of z(t). You just need know how to express the Laplace transform of dz(t)/dt and integral(z(t)) (using bad notation) in terms of Z(s). You will find these relationships in your class notes or text book or any number of on line sources. Once you know how to do that, you'll be able to solve each of those equations for the ratio Y(s)/U(s). At that point you can use ss() to find a (not "the") state space representation.
For example, suppose you found: Y(s)/U(s) = (2s + 1)/(s^2 + s + 2). You can find a state space model as
ss(tf([2 1],[1 1 2]))
ans = A = x1 x2 x1 -1 -2 x2 1 0 B = u1 x1 2 x2 0 C = x1 x2 y1 1 0.5 D = u1 y1 0 Continuous-time state-space model.
But you'll have to find Y(s)/U(s) first.
Problem g is trickier. There you'll have to find the matrix M(s) such that [Y1(s);Y2(s)] = M(s)*[U1(s);U2(s), then express M as a tf object, and then use ss(M).

5 commentaires

Thank you for your help.
Is there any way to automatically do the steps of finding the Laplace and solving for Y/U? I can do these by hand, but I'm just trying to see if I can do it in MATLAB (for example, I learned how to use Simulink to draw the block diagram of the system and from then get transfer functions/state-space).
I've already graduated, I'm using these questions to learn/practice MATLAB.
If you show how you did, for example, (f) by hand, we can then see how to carry out the same steps in Matlab.
Here's the solution of f by hand:
The problem I'm having on MATLAB is that, when I type the system as a differential equation, I don't know how I can get the Laplace transform in a way where I can simplify for Y/U.
I'm just trying to learn how I can do the first four lines on the image above, in MATLAB.
Here you go
syms y(t) u(t) tau
eqn = diff(y(t),t,2)+2*diff(y(t),t) + y + int(y(tau),tau,0,t) == diff(u(t),t) + 5*u(t)
eqn(t) = 
Leqn = laplace(eqn)
Leqn = 
syms Dy0
Leqn = subs(Leqn,subs(diff(y(t), t), t, 0),Dy0)
Leqn = 
Leqn = subs(Leqn,[y(0) Dy0 u(0)],[0 0 0])
Leqn = 
syms Y U s
Leqn = subs(Leqn,[laplace(y(t),t,s) laplace(u(t),t,s)],[Y U])
Leqn = 
Y = solve(Leqn,Y)
Y = 
H(s) = Y/U
H(s) = 
H = simplify(H)
H(s) = 
Thank you very much for your help.

Connectez-vous pour commenter.

Plus de réponses (1)

The following approach may be useful. State equations for the classical ordinary matrix differential equations
[M]{yddot} + [C]{ydot} + [K]{y} = [F]{q}
are given by:
[0] [I] [0]
{xdot} = [A]{x} + [B]{u] = {x} + {u}
-inv[M] [K] -inv[M] [C] inv[M] [C]

Produits

Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by