Borrar filtros
Borrar filtros

How to get y(k) values of a difference equation?

1 visualización (últimos 30 días)
José Luis| Pérez Santillán
José Luis| Pérez Santillán el 18 de Abr. de 2022
Editada: Harshal Ritwik el 13 de Jun. de 2023
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.

Respuestas (1)

Harshal Ritwik
Harshal Ritwik el 12 de Jun. de 2023
Editada: Harshal Ritwik el 13 de Jun. de 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 comentarios
Paul
Paul el 12 de Jun. de 2023
Should the values of y(1) and y(2) reversed?
Harshal Ritwik
Harshal Ritwik el 13 de Jun. de 2023
Editada: Harshal Ritwik el 13 de Jun. de 2023
Hi Paul!
Yes I missed that we need to do that
I have done the changes.
Thanks

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by