MATLAB: Beginner – can’t get plot/graph of “discrete logistic model”…

discrete logistic modellogisticplotplotting

I am a beginner MATLAB user and am working on the following example:
++++++++++++++++++++++++++++
A very interesting iterative relationship much studied recently is defined by
y(k+1) = r*y(k)*(1 − y(k))
(this is a discrete form of the well-known logistic model). Given y0 and r , successive yk ’s may be easily computed. For example, if y0 = 0.2 and r = 1, then y1 = 0.16, y2 = 0.1334, and so on. This formula is often used to model population growth in cases where growth is limited, restricted by shortages of food, living area, and the like. yk exhibits fascinating behavior, known as mathematical chaos, for values of r between 3 and 4 (independent of y0).Write a program that plots yk against k (as individual points). Values of r that give particularly interesting graphs are 3.3, 3.5, 3.5668, 3.575, 3.5766, 3.738, 3.8287, and many more that can be found by patient exploration.
++++++++++++++++++++++++++++
I have written a code but the resulting graph doesn't seem to be particularly interesting for any values. Is there something wrong in my code? If so, what? I am clumsy with indexing but it's not obvious to me what's gone awry. Here is the code:
++++++++++++++++++++++++++++
r=1 %at first, then values from 3-4
for k=1:20;
y(k+1)=r*y(k)*(1-y(k));
end
plot(k,y,'o')
++++++++++++++++++++++++++
EDIT: I think maybe I'm using the wrong plotting function? Here's another similar example where I'm having the same problem. Can't see what is wrong with my code 🙁
++++++++++++++++++++++++++
PROBLEM:
A rather beautiful fractal picture can be drawn by plotting the points (xk , yk ) generated by the following difference equations
x(k+1) = y(k) (1 + sin 0.7*x(k) ) − 1.2*sqrt(x(k)),
y(k+1) = 0.21 − x(k),
starting with x0 = y0 = 0. Write a program to draw the picture (plot individual points; do not join them).
++++++++++++++++++++++++++
CODE:
for k=0:20
x(k+1)=y(k)*(1+sin(0.7*x(k)))-1.2*sqrt(abs(x(k)));
y(k+1)=0.21-x(k);
end
plot(x,y,'o')

Best Answer

In your first example, you haven't shown us what value you used for y(1). Make sure to set
y(1) = 0.2;
before running the loop. The assignment says that the function will exhibit chaos "independent of y0", but really y0 has to be >0 and <1 to exhibit the patterns, so if you start at, for example, 1, you're going to get a very boring plot.