fplot and laplace transform
Show older comments
i have a system given in state space representation ( matrices A,B,C,D in the following code) and i need to plot the steady state output given the input vector u = [sin(t) 0]; i have written the following code:
A = [-4 1 0; 1 -2 -2; 0 2 -2];
B = [1 1; 0 1; 1 0];
C = [1 0 1; 1 1 2];
D = [1 0; 0 0];
s = sym('s');
G = C * inv(s*eye(size(A,1)) - A) * B + D;
t = sym('t');
u = [sin(t) 0];
U = laplace(u1);
Y = G*U1';
y = ilaplace(Y1);
fplot(y(1))
fplot(y(2))
however, Matlab doesn't print anything and gives me a warning; moreover, if i try to print the expression of y, Matlab gives me an "implicit" expression in the sense that it is not a function of the symbolic variable t, but something like ilaplace(function(s)); can someone help me?
6 Comments
Paul
on 8 Apr 2023
Hi Luca,
The posted code has the line
U = laplace(u1)
but u1 isn't defined?
The system will only have a steady state output if it is stable. So stability should always be checked first.
Assuming the system is stable, are you supposed to plot only the steady state output? Or are you supposed to plot the full output in response to the input until the output reaches close to steady state?
If the former, there's really no need to go through the inverse Laplace transform if you've learned about the theory of steady state output to sinusoidal inputs. I guess it depends on the intent of the problem .....
Luca Virecci Fana
on 8 Apr 2023
i am explicitely requested to compute the steady state response using the laplace and inverse laplace transform
Does that mean that you have to compute Laplace transform of the output, then compute the inverse Laplace transform, then extract the steady state output, in closed form? If so, it will be difficult, if even feasible, to find the closed form, inverse Laplace transform of a fifth order response. Are you sure that's what you're supposed to do?
A = [-4 1 0; 1 -2 -2; 0 2 -2];
B = [1 1; 0 1; 1 0];
C = [1 0 1; 1 1 2];
D = [1 0; 0 0];
syms s t
G = C * inv(s*eye(size(A,1)) - A) * B + D;
u = [sin(t); 0];
U = laplace(u);
Y = simplify(G*U)
y = ilaplace(Y)
Matlab can't find the full, closed form solution. But, if you look carefully you can extract the steady state solution if that's all you need.
Luca Virecci Fana
on 8 Apr 2023
Paul
on 8 Apr 2023
Yes, that would be correct, if it were feasible. The part of the problem statement about using Inverse Laplace Transforms is the part that's troubling. All you really need to solve this problem is G(s). You don't need the Laplace transform of U and you don't need the inverse Laplace transform of Y. So it's still not clear to me what the problem statement is really expecting you to do.
Luca Virecci Fana
on 8 Apr 2023
Accepted Answer
More Answers (1)
Based on the comment thread in the question, I think the best you can do symbolically would be some something like this:
A = [-4 1 0; 1 -2 -2; 0 2 -2];
eig(A)
B = [1 1; 0 1; 1 0];
C = [1 0 1; 1 1 2];
D = [1 0; 0 0];
syms s t
G = C * inv(s*eye(size(A,1)) - A) * B + D;
u = [sin(t); 0];
U = laplace(u);
Y = simplify(G*U)
y = ilaplace(Y)
If we look carefully at the two elements of y we see that each has terms in sin(t) and cos(t) and then a bunch of other stuff. That other stuff comes from the impulse response of the plant, which all decays to zero becasue the plant is stable (all the eigenvalues of A have negative real parts). We can see this more clearly by
vpa(y,5)
Every exponential term will decay to zero in steady state. Hence, the steady state output are the terms that do not decay to zero, i.e.,
yss = [67/44*sin(t) - 3/44*cos(t); 15/22*sin(t)]
Verify the answer based on mag and phase of G
G1 = subs(G,s,1j)
M = abs(G1)
P = angle(G1)
simplify(yss(1) - M(1,1)*sin(t + P(1,1)))
6 Comments
Walter Roberson
on 8 Apr 2023
At some point, I posted code to locate sum of root() and expand those, so it would be possible to get a version of y without the summation or root. It would be a bit ugly though.
Paul
on 8 Apr 2023
Would that be different than vpa(y) ?
Walter Roberson
on 8 Apr 2023
Edited: Walter Roberson
on 8 Apr 2023
The code should be able to get the full symbolic version of y.
Which, to be sure, would probably be mostly unreadable. The meaning of the full symbolic expression of roots of a cubic gets ugly. It is only useful for completionists, or in rare cases for proving complicated identities.
Luca Virecci Fana
on 8 Apr 2023
Paul
on 8 Apr 2023
In short, yes. Those terms can be neglected once you realize where they come from and that they will all decay to zero. Therefore, the steady state solution is composed of the sin(t) and cos(t) terms that don't decay to zero.
Because we know the system is stable, the steady state solution can be obtained thusly.
A = [-4 1 0; 1 -2 -2; 0 2 -2];
B = [1 1; 0 1; 1 0];
C = [1 0 1; 1 1 2];
D = [1 0; 0 0];
syms s t
u = [sin(t); 0];
U = laplace(u)
G = C * inv(s*eye(size(A,1)) - A) * B + D;
G = simplify(G);
yss = subs(G(:,1),s,1i)/(1i + 1i)*ilaplace(1/(s - 1i)) + subs(G(:,1),s,-1i)/(-1i - 1i)*ilaplace(1/(s + 1i));
yss = rewrite(yss,'sincos')
Though I don't think it's needed to answer this specific question, here's an approach to get the full, symbolic form of y. It takes advantage of the fact that the eigenvalues of A are distinct and can be computed symbolically.
e = eig(sym(A))
Y = simplify(G*U)
e = [e ; sym(1i) ; sym(-1i)];
y1 = 0;
y2 = 0;
num1 = numden(Y(1));
num2 = numden(Y(2));
for ii = 1:5
y1 = y1 + subs(num1/prod(s-e(e~=e(ii))),s,e(ii))*ilaplace(1/(s-e(ii)));
y2 = y2 + subs(num2/prod(s-e(e~=e(ii))),s,e(ii))*ilaplace(1/(s-e(ii)));
end
y1
y2
Verify that [y1;y2] == y as computed from ilaplace
y = ilaplace(Y);
figure
subplot(211);
fplot(real([y1-y(1) , y2 - y(2)]),[0 20])
subplot(212);
fplot(imag([y1-y(1) , y2 - y(2)]),[0 20])
Categories
Find more on Mathematics 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!



















