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

1 次查看(过去 30 天)
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 个评论
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