plot the output c(t) using mathlab and show setting time on you graphf

2 次查看(过去 30 天)
syms t tau;
A = [0 2; -2 -5];
B = [0; 1];
C = [2 1];
x0 = [1; 2];
Phi_t = expm(A*t);
x_h = Phi_t * x0;
u_tau = 1; % Unit step function
x_p = int(Phi_t * B, tau, 0, t);
x_t = x_h + x_p;
y_t = C * x_t;
disp('State-transition matrix Phi(t):');
State-transition matrix Phi(t):
disp(Phi_t);
fplot(Phi_t(1,1))
disp('Homogeneous solution x_h(t):');
Homogeneous solution x_h(t):
disp(x_h);
fplot(x_h)
disp('Particular solution x_p(t):');
Particular solution x_p(t):
disp(x_p);
disp('Full state vector x(t):');
Full state vector x(t):
disp(x_t);
disp('Output y(t):');
Output y(t):
disp(y_t);

回答(1 个)

Torsten
Torsten 2024-5-26
编辑:Torsten 2024-5-26
Use "fplot" as done in your code above.
  2 个评论
cf
cf 2024-5-26
移动:Sam Chak 2024-5-26
A=1
B=-1
inverse laplance of 1/s=1
inverse laplance of 1/(s+5)=e^-5t
c(t)= 1+e^-5t
setting time is 0.7832
Sam Chak
Sam Chak 2024-5-26
Hi @cf
The system you originally provided in your question is linear and the input signal is a unit step function. However, there is discrepancy in the results. Can you rectify the issue?
syms t tau;
A = [0 2; -2 -5];
B = [0; 1];
C = [2 1];
x0 = [1; 2];
Phi_t = expm(A*t);
x_h = Phi_t * x0;
u_tau = 1; % Unit step function
x_p = int(Phi_t * B, tau, 0, t)
x_p = 
x_t = x_h + x_p;
y_t = C * x_t;
% disp('State-transition matrix Phi(t):');
% disp(Phi_t);
% fplot(Phi_t(1,1))
%
% disp('Homogeneous solution x_h(t):');
% disp(x_h);
% % fplot(x_h)
%
% disp('Particular solution x_p(t):');
% disp(x_p);
% disp('Full state vector x(t):');
% disp(x_t);
disp('Output y(t):');
Output y(t):
disp(y_t);
figure
fplot(y_t, [0, 6]), hold on
%% parameters
A = [0, 2; -2, -5];
B = [0; 1];
C = [2, 1];
x0 = [1; 2]; % initial values: x1(0) = 1, x2(0) = 2
u_tau = 1; % Unit step function
%% state-space representation
function [dxdt, y] = stateSpace(t, x, A, B, C, u_tau)
dxdt = A*x + B*u_tau; % state equation
y = C*x; % output equation, check: y(0) = 2*x1(0) + 1*x2(0) = 4
end
%% call ode45 solver
tspan = [0, 6];
[t, x] = ode45(@(t, x) stateSpace(t, x, A, B, C, u_tau), tspan, x0);
[~, y] = stateSpace(t', x', A, B, C, u_tau);
plot(t, y, '-.', 'linewidth', 1.5, 'color', '#FA477A'), grid on, xlabel('t'), ylabel('y(t)')
legend('Manual Integration', 'Numerical Integration')
title('Output response, y(t)')

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by