フィルターのクリア

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 Center および File ExchangeGet 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