discrete time histories generation
1 view (last 30 days)
Show older comments
how can I generate discrete time series? for part C (image below) this is my attempt:
omega = sqrt(2);
zeta = 1/sqrt(2);
sympref('AbbreviateOutput', false);
syms x(t) y(t) u
eqn = diff(x, 2) + 2*zeta*omega*diff(x) + (omega^2)*x == (omega^2)*u;
[V, S] = odeToVectorField(eqn)
A = [0 0; -2 -2];
B = [2; 0];
C = [1 0];
D = 0;
sys = ss(A, B, C, D)
However, for part D, not sure what would be a right approach? Any help will be greatly appreciated. Thanks much.
0 Comments
Answers (1)
arushi
on 18 Oct 2023
Hi Cesar,
I understand that you want to generate the discrete time series for part D using the results of the variables in part C.
Please find the code below for the solution of part C in which the values A, B, C, D are used as calculated in the part C :
% Define the parameters
omega = sqrt(2);
zeta = 1/sqrt(2);
w = 2*pi/100;
N_TI = 100;
N_T2 = 50;
% Initialize variables
x_TI = zeros(1, N_TI);
x_T2 = zeros(1, N_T2);
% Generate discrete-time histories for TI system
for k = 3:N_TI
u = sign(cos(2*w*k)); % Input signal
x_TI(k) = -2*x_TI(k-1) - 2*x_TI(k-2) + 2*u; % Update state variable
end
% Generate discrete-time histories for T2 system
for k = 3:N_T2
u = sign(cos(2*w*k)); % Input signal
x_T2(k) = -2*x_T2(k-1) - 2*x_T2(k-2) + 2*u; % Update state variable
end
% Plot the results
k_TI = 0:N_TI-1;
k_T2 = 0:N_T2-1;
figure;
hold on;
plot(k_TI, x_TI, 'b', 'LineWidth', 1.5);
plot(k_T2, x_T2, 'r', 'LineWidth', 1.5);
xlabel('k');
ylabel('x(k)');
legend('TI system', 'T2 system');
title('Discrete-time histories');
Hope this answer helps.
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!