物流地图绘图问题

时间:2016-04-06 19:53:37

标签: matlab ode nonlinear-functions

我是MATLAB的新手,我试图在[0,4]中绘制λ的逻辑映射x =λx(1-x),从[0,1]绘制初始条件。但出于某种原因,我不断得到一个非常奇怪的情节。

Weird plot

我不认为它应该是这样的。可能是我的代码错了吗?

任何帮助都可以,谢谢!

我的代码:

startL = 0; # The starting value of lambda
finalL = 4; # The final value of lambda
N = 1000; # The number of values of lambda points
          # between starting value and final value
          # of lambda. (optional)


L = linspace(startL,finalL,N); # A row vector of N lambda
                               #  points between startL and finalL.
M = 1000; # The number of iterations

 # Loop trough the values of lambda
 for k = 1:length(L)

   # allocate memory for x
   x = zeros(1,M+1);
   x(1) = 0.3; # Initial condition: x_0, from [0,1].

   results = zeros(1,M+1);
   # Iteration scheme for current lamda
   for m = 1:M
      x(m+1) = L(k)*x(m)*(1 - x(m));
      results(k,m) = x(m+1);
  end;
end;

plot(L, results, 'b.');
xlabel('\lambda');
ylabel('x_n');
title('Logistic Map');

1 个答案:

答案 0 :(得分:2)

results=zeros(1, M+1);
对于for循环

中的每个k值初始化

在for循环开始之前初始化它:

 results = zeros(N, M+1);
 for k = 1:length(L)

   % allocate memory for x
   x = zeros(1,M+1);
   x(1) = 0.3; % Initial condition: x_0, from [0,1].


   % Iteration scheme for current lambda
   for m = 1:M
      x(m+1) = L(k)*x(m)*(1 - x(m));
      results(k,m) = x(m+1);
   end;
end