필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
José Luis| Pérez Santillán
José Luis| Pérez Santillán 2022년 4월 18일
편집: Harshal Ritwik 2023년 6월 13일
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.

답변 (1개)

Harshal Ritwik
Harshal Ritwik 2023년 6월 12일
편집: Harshal Ritwik 2023년 6월 13일
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
Paul
Paul 2023년 6월 12일
Should the values of y(1) and y(2) reversed?
Harshal Ritwik
Harshal Ritwik 2023년 6월 13일
편집: Harshal Ritwik 2023년 6월 13일
Hi Paul!
Yes I missed that we need to do that
I have done the changes.
Thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by