Is MATLAB solving Difference equations ?

21 ビュー (過去 30 日間)
msh
msh 2013 年 7 月 6 日
コメント済み: Charity Reed 2020 年 12 月 8 日
Hi
I am wondering whether MATLAB is able to solve DIFFERENCE (recursive) equations, not differential ones. For example, difference equations as those frequently encountered in Economics.
Is a there a proxy method to do it?
Thanks
  1 件のコメント
Ahmed ElTahan
Ahmed ElTahan 2016 年 3 月 25 日
Here is a function I have built to calculate it with added example. https://www.mathworks.com/matlabcentral/fileexchange/56142-output-estimation-difference-equation

サインインしてコメントする。

採用された回答

Samir A. Farag
Samir A. Farag 2014 年 10 月 24 日
編集済み: Walter Roberson 2017 年 2 月 22 日
Let us solve this difference equation:
c(k+2)-1.3c(k+1)+0.4c(k)=r(k) % c(0)=0 and c(1)=0.
Where, c(k) represents the system output and r(k) the system input and both of them in discrete.
This example is solved by three MATLAB codes:
----------------
1-Solving the difference equation by obtaining the inverse z-transform of c(z) after substituting by the input at which you solve it and initial conditions:
delta=[1 zeros(1 , 5)]; num=[0 0 1]; den=conv([1 -1.3 0.4],[1 -1]);
c=filter(num , den , delta)
----------------------------
2- Solving the difference equation using filter function:
% c(k+2)-1.3c(k+1)+0.4c(k)=r(k) % c(0)=0 and c(1)=0.
num=[0 0 1]; den=[1 -1.3 0.4];
r=[1 ones(1,5)]; % input signal, in this case is unit step signal
c=filter(num , den , r)
---------
3-Solving the difference equation – at step input – using dstep function which used in case of zero initial condition:
k=0:5; num=[0 0 1]; den=[1 -1.3 0.4]; c=dstep(num,den, length(k))
---------------
When you run the three codes, you will find that all give the same results. Also, I solved this problem by hand and the results match that calculated by MATLAB. Let me know if you need it.
Mr. Eng. Samir A. Farag, Teaching Assistant at H.T.I, Egypt.
  1 件のコメント
Charity Reed
Charity Reed 2020 年 12 月 8 日
What is dstep?

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2013 年 7 月 6 日
There is the filter() command. If you were looking for a symbolic solution, you might find something in the Symbolic Math Toolbox.
  3 件のコメント
msh
msh 2013 年 7 月 6 日
I see your point, i will try to see whether fits my purpose. Thank you
Samir A. Farag
Samir A. Farag 2014 年 10 月 23 日
編集済み: Walter Roberson 2017 年 2 月 22 日
% Mr. Azzi Abdelmalek, I have some notes on your answer.
%x(n+2)-1.3x(n+1)+0.4x(n)=u(n) % x(0)=0 and x(1)=0.
num=[0 0 1]; den=[1 -1 0.25];
k=0:1:5; % discrete time
% According to unit step definition, u(n)=1 for n>=0 and zero otherwise
% but using the heaviside function - and n is discrete and integer -
% contradicts this definition
% because it equals 0.5 - and not one - at n=0.
% So, to use k in discrete - and integre, i.e. 0, 1 , 2, .. etc,
% heaviside is not the proper function and you have to define it like my
% answer
x=[1 ones(1,5)]; % This yields outputs from y(0) to y(5)
y=filter(num,den,x)
% Also, the solution of difference equation is in discrete, so, to plot it,
use stem function
stem(k,y), grid
%Mr. Samir A. Farag, Teaching Assistant at H.T.I, Egypt

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by