Matlab 'For' loop and line plotting [Beginners question]
By Michael Henderson •
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;
endIs 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$$
$\endgroup$ 01 Answer
$\begingroup$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); $\endgroup$ 1