How to get y(k) values of a difference equation?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I need to know how do I get first 10 values of y(k) (from 0 to 9) in a difference equiation by Matlab, I got on paper but I need to know how to get it by Matlab. I have this difference equation:
0.5y(k - 2) - 1.5y(k - 1) + y(k) = µ(k) - µ(k - 1); if y(-1) = 2, y(-2) = 1 and µ(k) is a step signal.
They ask me solve it by Matlab but I don´t know how to do it, I do it on paper to verify the results on Matlab but I didn´t find how to solve it. I tried to search on my own but I didn't find something relevant, you are my last hope people. Thank you for help me.
0 commentaires
Réponses (1)
Harshal Ritwik
le 12 Juin 2023
Modifié(e) : Harshal Ritwik
le 13 Juin 2023
Hi,
As per my understanding of your question you want to know how we can use display the desired 10 values of y(k) with the help of the given initial conditions. The following Code Snippet may help.
%Code Section
% Define the range of data you want
k = 0:9;
% Define initial conditions here y(-1) is taken as y(1) to get %all indexes to positive side
y = zeros(1, length(k)+2);
y(1) = 1;
y(2) = 2;
% Defining the step signal
mu = [ones(1, length(k)+2) 0];
% Implement the difference equation for k = 3 and onwards
for n = 3:length(k)+2
y(n) = (mu(n) - mu(n-1) + 1.5*y(n-1) - 0.5*y(n-2)) / 1;
end
% Display the first 10 values in the Command Window
disp(y(3:12));
Please refer to the following documentation for more information
I hope it helps!
Thanks.
2 commentaires
Harshal Ritwik
le 13 Juin 2023
Modifié(e) : Harshal Ritwik
le 13 Juin 2023
Hi Paul!
Yes I missed that we need to do that
I have done the changes.
Thanks
Voir également
Catégories
En savoir plus sur Get Started with MATLAB 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!