Trouble with difference equation

조회 수: 1 (최근 30일)
Debanita Das
Debanita Das 2019년 5월 22일
댓글: Debanita Das 2019년 5월 22일
clc; close all; clear all;
b=0.9; d=0.25;
nn=200;
t=[0:0.1:100];
for a=0:0.01:11
for n=1:nn
x(1)=0.4;
y(1)=2.9;
x(n+1)=x(n)+(d*((a*x(n))*(1-x(n))-((b*x(n)*y(n))/(x(n)+y(n)))));
y(n+1)=y(n)+(d*(((b*x(n)*y(n))/(x(n)+y(n)))-y(n)));
stem(y,x)
end
end
i have been trying to run this code in order to plot difference equation curves but this code isn't yielding any output. Can anyone suggest any other codes or point out my mistake?

채택된 답변

Raj
Raj 2019년 5월 22일
편집: Raj 2019년 5월 22일
1) For which value of 'a' are you trying to plot the stem graph? If for all the values from a=0:0.01:11 then shift the plot outside first for loop like this:
for a=0:0.01:11
for n=1:nn
x(1)=0.4;
y(1)=2.9;
x(n+1)=x(n)+(d*((a*x(n))*(1-x(n))-((b*x(n)*y(n))/(x(n)+y(n)))));
y(n+1)=y(n)+(d*(((b*x(n)*y(n))/(x(n)+y(n)))-y(n)));
end
stem(y,x)
hold on
end
If you want to plot for a particular value of 'a' then the first for loop makes no sense.
2) what is the use of 't'?
3) Use of close all, clear all etc are not recommended. See here.
  댓글 수: 1
Debanita Das
Debanita Das 2019년 5월 22일
Thank you so much for rectifying my mistake.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by