Use "fplot" as done in your code above.
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):');
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):');
disp(y_t);
0 个评论
回答(1 个)
Torsten
2024-5-26
编辑:Torsten
2024-5-26
2 个评论
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_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):');
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)')
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!