Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
cf
cf am 26 Mai 2024
Kommentiert: Sam Chak am 26 Mai 2024
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);

Antworten (1)

Torsten
Torsten am 26 Mai 2024
Bearbeitet: Torsten am 26 Mai 2024
Use "fplot" as done in your code above.
  2 Kommentare
cf
cf am 26 Mai 2024
Verschoben: Sam Chak am 26 Mai 2024
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 am 26 Mai 2024
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)')

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by