Altering Matlab Code for a Logistic Map Cobweb Plot

Click For Summary
SUMMARY

The discussion focuses on modifying existing Matlab code to create a cobweb plot for a logistic map defined by the equation N_{t+1} = (1+r)N_t/(1+rN_t). The original code computes the trajectory using a parameter 'a' set to 3.0 and an initial condition of 0.2 over 40 iterations. Users are advised to utilize MATLAB Online or the open-source Freemat for executing the code, noting that MATLAB Online requires a valid license while Freemat offers a free alternative with some limitations.

PREREQUISITES
  • Understanding of logistic maps and their mathematical representation
  • Familiarity with Matlab programming and syntax
  • Knowledge of plotting functions in Matlab
  • Basic concepts of iterative processes in numerical analysis
NEXT STEPS
  • Explore how to implement custom equations in Matlab for dynamic systems
  • Learn about advanced plotting techniques in Matlab for data visualization
  • Investigate the differences between Matlab and Freemat for compatibility
  • Study the implications of using MATLAB Online versus offline installations
USEFUL FOR

Matlab users, data scientists, educators, and anyone interested in visualizing mathematical models through cobweb plots and logistic maps.

Dustinsfl
Messages
2,217
Reaction score
5
I found some Matlab code that works. However, I am not sure how to alter it for my needs.

How can I make the code work for this:##N_{t+1} = \frac{(1+r)N_t}{1+rN_t}##What needs to be changed?
Matlab:
%%% MAKES A COBWEB PLOT FOR A LOGISTIC MAP

% compute trajectory
a=3.0;          % parameter
x0=0.2;         % Initial condition 
N=40;           % Number of iterations
x(1) = x0;    
for ic=1:N
 x(ic+1) = a*x(ic)*(1-x(ic)); 
end

% plot the map function and the line y=x
clf;
t = 0:0.01:1;
plot(t,a*(t.*(1-t))); hold on;
 axis('square'); axis([0 1 0 1]);
 set(gca,'XTick',(0:0.1:1),'YTick',(0:0.1:1))
 grid on;

 fplot('1*y',[0 1],'r');

%%%%%% STEP 3: PLOT COBWEB
 line([x(1) x(1)],[0 x(2)],'Color','g') 
  plot(x(1), x(1),'ko');
 for ic=1:N-1
  line([x(ic) x(ic+1)],[x(ic+1) x(ic+1)],'Color','g')  
  line([x(ic+1) x(ic+1)],[x(ic+1) x(ic+2)],'Color','g')
  plot(x(ic+1), x(ic+1),'ko');
 end
 line([x(N) x(N+1)],[x(N+1) x(N+1)],'Color','g')
 
  %%%%%% STEP 4: SIGN THE PLOT
 at=text(0.1,0.82,['a=',num2str(a)]); set(at,'FontSize',12);
 
Last edited by a moderator:
Physics news on Phys.org
  • Like
Likes   Reactions: Greg Bernhardt
jedishrfu said:
One might be able to run this on the MATLAB Online service
MATLAB online is not free. You have to have a valid license to be able to use that. For instance, my student license entitles me to download MATLAB for offline use forever even if I do not renew (I won't get the updated version, only the one that was latest when the license expired). MATLAB Android app is, however, free to use, but the speed depends on your internet connectivity as the interpreter is on the server.
 
  • Like
Likes   Reactions: jedishrfu

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K