The orbit diagram for the logistic family

6 visualizzazioni (ultimi 30 giorni)
Zoe Erickson
Zoe Erickson il 2 Apr 2019
Risposto: BhaTTa il 14 Ago 2025
I can't seem to figure out what to do to make this code for the orbit diagram for the logistic family. I'm very new to MatLab, could someone help me out? This is what I have:
close all;
clear all;
hold on;
for r = linspace(3,4,1000)
for P_initial = linspace(0.1, 0.9, 100)
num_iters = 250;
P(1) = P_initial;
for n=1:(num_iters - 1)
P(n + 1) = r*P(n)*(1 - P(n));
end
plot(r,P(num_iters),'.')
axis([0,4,0,2]);
end
end

Risposte (1)

BhaTTa
BhaTTa il 14 Ago 2025
Hey @Zoe Erickson, Here’s a simple way to turn your loops into a proper bifurcation (orbit) diagram for the logistic map
Key idea: for each value of the parameter r, iterate the logistic map many times, discard a “transient” of iterations, and plot the remaining values of P against that r.
I am attaching the code below for referecne, modify it accordingly:
close all
clear
figure
hold on
% Parameter sweep for r
r_values = linspace(3,4,1000);
% Number of total iterations per r
num_iters = 300;
% Number of last points to plot (after transient)
num_plot = 100;
% Initial condition(s)
P0 = 0.5;
for r = r_values
% Preallocate
P = zeros(1,num_iters);
P(1) = P0;
% Iterate logistic map
for n = 1:num_iters-1
P(n+1) = r * P(n) * (1 - P(n));
end
% Plot only the last num_plot points (to avoid transients)
idx = (num_iters - num_plot + 1):num_iters;
plot(r * ones(1,num_plot), P(idx), '.k', 'MarkerSize', 1);
end
xlabel('r')
ylabel('Population P_n')
title('Bifurcation Diagram of the Logistic Map')
axis([3 4 0 1])
box on
hold off

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by