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

19 vues (au cours des 30 derniers jours)
cf le 26 Mai 2024 à 9:53
Commenté : Sam Chak le 26 Mai 2024 à 15:37
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);
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (1)

Torsten le 26 Mai 2024 à 9:59
Modifié(e) : Torsten le 26 Mai 2024 à 10:01
Use "fplot" as done in your code above.
##### 2 commentairesAfficher AucuneMasquer Aucune
cf le 26 Mai 2024 à 10:01
Déplacé(e) : Sam Chak le 26 Mai 2024 à 14:37
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 le 26 Mai 2024 à 15:37
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)')

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Calculus dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by