fplot and laplace transform

19 views (last 30 days)
Luca Virecci Fana
Luca Virecci Fana on 8 Apr 2023
Edited: Paul on 10 Apr 2023
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
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
Luca Virecci Fana on 8 Apr 2023
I know that I could use the frequency response theorem to compute the steady state output and I should just compute the magnitude and the phase of the components of G at frequency 1 to do that, but this is the assignment

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 8 Apr 2023
I am not certain what the problem is. The inversion appears to be correct, and the result is what I would expect it to be. Since Laplace transforms are defined for , it is necessary to define that as the second argument to fplot.
After the inversion, ‘y’ is a function of ‘t’ as expected, and the plot appears to be appropriate —
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(u.');
Y = G*U;
y = ilaplace(Y)
y = 
figure
fplot(y, [0 10])
grid
xlabel('t')
ylabel('System Output')
legend('y_1','y_2', 'Location','best')
Is this the result you want?
.
  8 Comments
Star Strider
Star Strider on 9 Apr 2023
The expression is being evaluated, however you need to use the vpa function to see the numeric result —
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(u.');
Y = G*U;
y = ilaplace(Y) % Function
y = 
y_3 = subs(y, t, 3) % Symbolic Solution
y_3 = 
y_3 = simplify(y_3, 500) % Simplified Symbolic Solution
y_3 = 
y_3 = vpa(y_3) % Numeric Symbolic Solution
y_3 = 
format long
y_3 = double(y_3) % Double Precision Solution (Can Be Used Outside Of The Symbolic Math Toolbox)
y_3 = 2×1
0.282757162323995 0.096723511065013
In other instances, the symbolic result is because MATLAB cannot find a numeric solution for a specific result, and so returns the symbolic expression. Sometimes, the simplify function can do this (with perhaps 500 or more permitted iterations), however other times, not (as in this instance).
.
Walter Roberson
Walter Roberson on 9 Apr 2023
If you need the full symbolic expression without the sum of roots in it, then see my comment to Paul's answer, where I link to code I posted before that will expand the expression. But the result will be messy, and will contain lots of terms like sqrt(sin(3)*(1-sqrt(5))^2*1i)/(sqrt(cos(7)^2+3i)) that very few people will be able to intuitively understand the purpose of.

Sign in to comment.

More Answers (1)

Paul
Paul on 8 Apr 2023
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)
ans =
-4.2483 + 0.0000i -1.8759 + 1.8822i -1.8759 - 1.8822i
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 = 
y = ilaplace(Y)
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)
ans = 
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)]
yss = 
Verify the answer based on mag and phase of G
G1 = subs(G,s,1j)
G1 = 
M = abs(G1)
M = 
P = angle(G1)
P = 
simplify(yss(1) - M(1,1)*sin(t + P(1,1)))
ans = 
0
  6 Comments
Paul
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.
Paul
Paul on 9 Apr 2023
Edited: Paul on 10 Apr 2023
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)
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')
yss = 
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))
e = 
Y = simplify(G*U)
Y = 
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
y1 = 
y2
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])

Sign in to comment.

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!