fplot and laplace transform
9 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Paul
2023 年 4 月 8 日
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.
採用された回答
Star Strider
2023 年 4 月 8 日
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)
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 件のコメント
Star Strider
2023 年 4 月 9 日
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_3 = subs(y, t, 3) % Symbolic Solution
y_3 = simplify(y_3, 500) % Simplified Symbolic Solution
y_3 = vpa(y_3) % Numeric Symbolic Solution
format long
y_3 = double(y_3) % Double Precision Solution (Can Be Used Outside Of The Symbolic Math Toolbox)
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
2023 年 4 月 9 日
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.
その他の回答 (1 件)
Paul
2023 年 4 月 8 日
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 件のコメント
Paul
2023 年 4 月 8 日
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
2023 年 4 月 9 日
編集済み: Paul
2023 年 4 月 10 日
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])
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




















