fplot and laplace transform

조회 수: 11 (최근 30일)
Luca Virecci Fana
Luca Virecci Fana 2023년 4월 8일
편집: Paul 2023년 4월 10일
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
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.
Luca Virecci Fana
Luca Virecci Fana 2023년 4월 8일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
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)
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
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 = 
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 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
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)
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
Paul
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
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)
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])

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by