How do you code this set of discrete difference equations using for loop?

조회 수: 3 (최근 30일)
Ruth Porter
Ruth Porter 2018년 11월 29일
답변: Md Muzakkir Quamar 2020년 11월 11일
This is where ive got so far with it, but it doesnt seem to be changing the values of x,y and z
%Parameters -- Keep as constants for now.
d = 0.001;
%Parameters - Varying values of a, b and r
a=2;
b=2;
r=3;
%Initial conditions
x(1)=2;
y(1)=2;
z(1)=2;
for n=1:10
x(n+1)=x(n)+(d*a)*(x(n)-y(n));
y(n+1)=y(n)+(d*r)*(x(n)-z(n))*(x(n)-y(n));
z(n+1)=z(n)+(d*((x(n)*y(n))-(b*z(n))));
end
figure(1),
subplot(3,1,1), hold on
plot(x(n), n)
xlabel('n');
subplot(3,1,2), hold on
plot(y(n), n)
xlabel('n');
subplot(3,1,3), hold on
plot(z(n), n)
xlabel('n');
  댓글 수: 1
Akira Agata
Akira Agata 2018년 11월 30일
편집: Akira Agata 2018년 11월 30일
I think it's due to your initial condition. If you change the initial condition, like x(1) = 1, y(1) = 2, z(1) = 3, then they will change as n increases.

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

답변 (1개)

Md Muzakkir Quamar
Md Muzakkir Quamar 2020년 11월 11일
you need to create an array for x(n), y(n), z(n) to store the values

카테고리

Help CenterFile Exchange에서 Dynamic System Models에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by