0
function  question2a(a,x)
  y=zeros(1000,1);
  y(1)=x;
  hold on;
  for j=2:1000
     y(j) = a*y(j-1)*exp(-y(j-1));
     plot(j, y);
  end
  hold off;
end

Is my code for a certain exercise, however I am not getting a line instead of a line I am getting a lot of dots. Can someone please explain me how I can fix this?

The function should replicate this:

$$y_{n+1}=\alpha \cdot y_{n} \cdot e^{-y_n}$$

$$y_1 = \alpha \cdot y_0 \cdot e^{-y_0}, \qquad y_2 = \alpha \cdot y_1 \cdot e^{-y_1} = \alpha \cdot \alpha \cdot y_0 \cdot e^{-y_0} \cdot e^{-\alpha \cdot y_0 \cdot e^{-y_0}}, \qquad \ldots$$

Surb
  • 55,662
Gauss
  • 41

1 Answers1

0

Advice Have a look the Matlab documentation center

Hint Run this code in a script and try to understand what is your problem.

z = rand(8,1);

figure
for i = 1:8
    plot(i,z(i));
    hold on;
end;
hold off;

figure
plot((1:8),z);

figure
plot(z);
Surb
  • 55,662
  • 1
    I got it, so stupid..if it is in the loop it will calculate and plot the graph for every point if it is outside the loop it will draw a line, thanks again! – Gauss Dec 04 '15 at 14:08