maximum Lyapunov exponent diagram

hello, I'm working on discrete dynamical system in 2 dimesntion
t'm trying to plot a digram a paramete versus the maximum lyapunov exponent, i searched more about it but didn't reach to anything.
any one have idea or could help me and thank you.

18 Comments

Hi @Noura,

To address your query, “I'm working on discrete dynamical system in 2 dimesntion t'm trying to plot a digram a paramete versus the maximum lyapunov exponent, i searched more about it but didn't reach to anything. any one have idea or could help me and thank you.”

The code snippet below simulates a dynamical system using the logistic map equation to calculate Lyapunov exponents. It computes the Lyapunov exponent for different parameter values, indicating the system's sensitivity to initial conditions. If you look at the resulting plot, it will show how the Lyapunov exponent changes concerning the system's parameters, providing insights into the system's chaotic behavior. This analysis can help you understand the system's stability and predictability based on Lyapunov exponents.

% Define your discrete dynamical system function

function x_next = dynamical_system(x, parameter)

    % Define your system here, for example:
    x_next = parameter * x * (1 - x);

end

% Function to calculate the Lyapunov exponent

function lyapunov = calculate_lyapunov(x, parameter, iterations)

    lyapunov = 0;
    for i = 1:iterations
        x = dynamical_system(x, parameter);
        lyapunov = lyapunov + log(abs(parameter * (1 - 2 * x)));
    end
    lyapunov = lyapunov / iterations;

end

% Define the range of parameter values

parameters = linspace(2.8, 4, 1000); % Adjust the range as needed

% Initialize arrays to store parameter values and corresponding Lyapunov

exponents

lyapunov_exponents = zeros(size(parameters));

% Iterate over each parameter value and calculate the Lyapunov exponent

for i = 1:length(parameters)

    lyapunov_exponents(i) = calculate_lyapunov(0.5, parameters(i), 1000); % 

Adjust the initial condition and iterations as needed

end

% Plot the parameter values against the maximum Lyapunov exponents

figure;

plot(parameters, lyapunov_exponents, 'b');

xlabel('Parameter Value');

ylabel('Maximum Lyapunov Exponent');

title('Parameter vs. Maximum Lyapunov Exponent Plot');

Please see attached plot.

Hope this helps answers your question.

function lyapunov = calculate_lyapunov(x, parameter, iterations) is this including with the code ? sorry for that question since i'm new to matlab.
function x_next = dynamical_system(x, d)
y_next = dynamical_system(y,d)
x_next = 3.4*x*(1-x)-x*y;
y_next = -0.2*y+d*x*y;
end
function lyapunov = calculate_lyapunov(x, d, iterations)
lyapunov = calculate_lyapunov(y, d, iterations)
lyapunov = 0;
for i = 1:iterations
x = dynamical_system(x, parameter);
y = dynamical_system(y, parameter);
lyapunov = lyapunov + log(abs(parameter * (1 - 2 * x)));
end
lyapunov = lyapunov / iterations;
end
parameters = linspace(2.8, 4, 1000); % Adjust the range as needed
lyapunov_exponents = zeros(size(parameters));
for i = 1:length(parameters)
lyapunov_exponents(i) = calculate_lyapunov(0.5, parameters(i), 1000);
end
figure;
plot(parameters, lyapunov_exponents, 'b');
xlabel('Parameter Value');
ylabel('Maximum Lyapunov Exponent');
title('Parameter vs. Maximum Lyapunov Exponent Plot');
can you check what i did please if you have time and thank you.
Hi @Noura,
To confirm, the function calculate_lyapunov(x, parameter, iterations) is indeed present which is responsible for calculating the Lyapunov exponent of a discrete dynamical system defined by the function dynamical_system(x, parameter). Please review my code snippet to find out. I will be addressing your next query shortly regarding, “ can you check what i did please if you have time and thank you.”
Ah ok I see it now.

Hi @Noura,

Please see attached results of your code regarding, “can you check what i did please if you have time and thank you.”

However, debugging and fixing your code, here is updated version, execute this code and visualize the plot. So, after visualizing plot, please tell me what is your analysis.

function [x_next, y_next] = dynamical_system(x, y, d)

    x_next = 3.4*x*(1-x)-x*y;
    y_next = -0.2*y+d*x*y;

end

% Define initial values for x, y, and d

x_initial = 0.5;

y_initial = 0.3;

d = 0.1;

% Call the dynamical_system function with initial values

[x_next, y_next] = dynamical_system(x_initial, y_initial, d);

% Display the results

disp('Results:');

disp(['x_next: ', num2str(x_next)]);

disp(['y_next: ', num2str(y_next)]);

function lyapunov = calculate_lyapunov(x, y, d, iterations)

    lyapunov = 0;
    for i = 1:iterations
        [x_next, y_next] = dynamical_system(x, y, d); % Corrected function call
        lyapunov = lyapunov + log(abs(d * (1 - 2 * x_next)));
        x = x_next; % Update x for the next iteration
        y = y_next; % Update y for the next iteration
    end
    lyapunov = lyapunov / iterations;

end

parameters = linspace(2.8, 4, 1000); % Adjust the range as needed

lyapunov_exponents = zeros(size(parameters));

for i = 1:length(parameters)

    lyapunov_exponents(i) = calculate_lyapunov(0.5, 0.5, parameters(i), 1000); 

end

figure;

plot(parameters, lyapunov_exponents, 'b');

xlabel('Parameter Value');

ylabel('Maximum Lyapunov Exponent');

title('Parameter vs. Maximum Lyapunov Exponent Plot');

noura
noura on 4 Aug 2024
Edited: noura on 4 Aug 2024
@Umar thanks for the respons, i tried the code and i'm getting this error
function [x_next, y_next] = dynamical_system(x, y, d)
x_next = 3.4*x*(1-x)-x*y;
y_next = -0.2*y+d*x*y;
end
x_initial = 0.4; % here is line 7
y_initial = 1;
d = 3.72;
[x_next, y_next] = dynamical_system(x_initial, y_initial, d);
disp('Results:');
disp(['x_next: ', num2str(x_next)]);
disp(['y_next: ', num2str(y_next)]);
function lyapunov = calculate_lyapunov(x, y, d, iterations)
lyapunov = 0;
for i = 1:iterations
[x_next, y_next] = dynamical_system(x, y, d); % Corrected function call
lyapunov = lyapunov + log(abs(d * (1 - 2 * x_next)));
x = x_next; % Update x for the next iteration
y = y_next; % Update y for the next iteration
end
lyapunov = lyapunov / iterations;
end
parameters = linspace(0, 4.5, 1000); % Adjust the range as needed
lyapunov_exponents = zeros(size(parameters));
for i = 1:length(parameters)
lyapunov_exponents(i) = calculate_lyapunov(0.5, 0.5, parameters(i), 1000);
end
figure;
plot(parameters, lyapunov_exponents, 'b');
xlabel('Parameter Value');
ylabel('Maximum Lyapunov Exponent');
title('Parameter vs. Maximum Lyapunov Exponent Plot');
noura
noura on 4 Aug 2024
Edited: noura on 4 Aug 2024
@Umar i changed it to this way
x_initial = 0.4; % here is line 7
y_initial = 1;
d = 3.72;
[x_next, y_next] = dynamical_system(x_initial, y_initial, d);
disp('Results:');
disp(['x_next: ', num2str(x_next)]);
disp(['y_next: ', num2str(y_next)]);
parameters = linspace(0, 4.5, 1000); % Adjust the range as needed
lyapunov_exponents = zeros(size(parameters));
for i = 1:length(parameters)
lyapunov_exponents(i) = calculate_lyapunov(0.5, 0.5, parameters(i), 1000);
end
figure;
plot(parameters, lyapunov_exponents, 'b');
xlabel('Parameter Value');
ylabel('Maximum Lyapunov Exponent');
title('Parameter vs. Maximum Lyapunov Exponent Plot');
function [x_next, y_next] = dynamical_system(x, y, d)
x_next = 3.4*x*(1-x)-x*y;
y_next = -0.2*y+d*x*y;
end
function lyapunov = calculate_lyapunov(x, y, d, iterations)
lyapunov = 0;
for i = 1:iterations
[x_next, y_next] = dynamical_system(x, y, d); % Corrected function call
lyapunov = lyapunov + log(abs(d * (1 - 2 * x_next)));
x = x_next; % Update x for the next iteration
y = y_next; % Update y for the next iteration
end
lyapunov = lyapunov / iterations;
end
actually it worked but i'm getting the wrong figure , this is what i got
and this is what i should get
Hi @Noura,
Could you please let me know where did you get the second plot from.
@Umar do you have an e-mail ?
Hi @noura,
I was told by one of the staff members that we cannot share our emails on this platform. Hope you understand.
@Umar i totally understand that , for the above problem if you could help me to fix the problem if you couldn't it's ok i appreciate all your help and the effort you put on this question.

Hi @noura,

It is not about matching plots, hope that you are aware that the Lyapunov exponent provides insights into the system's sensitivity to initial conditions. So, in chaotic systems, positive Lyapunov exponents indicate sensitive dependence on initial conditions, while negative exponents suggest convergence towards a stable state. When you observe the plot, the system may exhibit chaotic behavior with positive Lyapunov exponents, indicating sensitivity to initial conditions. As the parameter value increases, the system dynamics may stabilize, leading to a decrease in the Lyapunov exponent, suggesting convergence towards a stable state. The calculate_lyapunov function is modified below to handle negative Lyapunov exponents by using subtraction instead of addition when updating the Lyapunov value. This adjustment is crucial for accurately capturing the behavior of the system, especially when dealing with convergence. To assess if the Lyapunov exponents are decreasing, we need to interpret the plotted data. By observing your plot, you need to observe if you see a decreasing Lyapunov exponent curve, it will signify that the system trajectories are converging towards a stable equilibrium which implies that perturbations in the system diminish over time, leading to stability. Conversely, an increasing Lyapunov exponent curve will show that the system trajectories are diverging, moving away from each other. This divergence indicates instability or chaotic behavior within the system.

% Modify the dynamical system function to induce convergence

function [x_next, y_next] = dynamical_system(x, y, d)

    x_next = 3.4*x*(1-x)-x*y;
    y_next = -0.2*y + d*x*y; % Adjusted dynamics for convergence

end

% Modify the Lyapunov exponent calculation for negative values

function lyapunov = calculate_lyapunov(x, y, d, iterations)

    lyapunov = 0;
    for i = 1:iterations
        [x_next, y_next] = dynamical_system(x, y, d);
        lyapunov = lyapunov - log(abs(d * (1 - 2 * x_next))); % Use subtraction for negative Lyapunov exponent
        x = x_next;
        y = y_next;
    end
    lyapunov = lyapunov / iterations;

end

Hope, this helps.

noura
noura on 4 Aug 2024
Edited: noura on 4 Aug 2024
that's a very useful information for anyone is studying a dynamical system thanks alot.
for the code you meant that i need to write it in that way ?
x_initial = 0.4;
y_initial = 1;
d = 3.72;
[x_next, y_next] = dynamical_system(x_initial, y_initial, d);
disp('Results:');
disp(['x_next: ', num2str(x_next)]);
disp(['y_next: ', num2str(y_next)]);
parameters = linspace(0, 4.5, 1000); % Adjust the range as needed
lyapunov_exponents = zeros(size(parameters));
for i = 1:length(parameters)
lyapunov_exponents(i) = calculate_lyapunov(0.5, 0.5, parameters(i), 1000);
end
figure;
plot(parameters, lyapunov_exponents, 'b');
xlabel('Parameter Value');
ylabel('Maximum Lyapunov Exponent');
title('Parameter vs. Maximum Lyapunov Exponent Plot');
function [x_next, y_next] = dynamical_system(x, y, d)
x_next = 3.4*x*(1-x)-x*y;
y_next = -0.2*y + d*x*y; % Adjusted dynamics for convergence
end
function lyapunov = calculate_lyapunov(x, y, d, iterations)
lyapunov = 0;
for i = 1:iterations
[x_next, y_next] = dynamical_system(x, y, d);
lyapunov = lyapunov - log(abs(d * (1 - 2 * x_next))); % Use subtraction for negative Lyapunov exponent
x = x_next;
y = y_next;
end
lyapunov = lyapunov / iterations;
end
@Umar i got the same picture but reversed
also one thing you said i It is not about matching plots but i'm using the same initial condition so i think they need to match.
That's why i'm confused.
Hi @noura,
Yes, when you execute this code and observe the plot, you will see a high Lyapunov Exponent which suggests chaotic behavior, where small changes in initial conditions lead to significant divergence. The fluctuations you will observed signify the system's transition between chaotic and non-chaotic behavior as the parameter varies. So, peaks in the Lyapunov Exponent indicate chaotic regimes, while decreases suggest more stable dynamics. After doing your analysis on this graph, you have to make decision if you want to stick with calculate_lyapunov function that is currently modified to handle negative Lyapunov exponents by using subtraction instead of addition.
@Umar yes i understand all of that, but my problem is why i'm not getting the same plot since i'm using the exact initial condition like i need to understand that.

Sign in to comment.

 Accepted Answer

Umar
Umar on 4 Aug 2024
Hi @noura,
To address your query, “but my problem is why i'm not getting the same plot since i'm using the exact initial condition like i need to understand that.”
You have to contact the source of information who gave you this attachment which was shared in your posted comments to find out what parameters did he or she change in the code to get this plot. As far, I have provided my knowledge based on the code provided by you and help you further understand and help out to achieve your goal.

2 Comments

@Umar yes i will do , and thank you so much for your help i apperciate it.
Hi @noura,
From looking at your code, it sounds like you are a motived person to pursue your goals. At this platform, the goal is to share knowledge and help each out each other. If you still have any other questions, please let me know. Also, if all your questions have been answered, you can click accept answer. Otherwise, I am still here to help you.

Sign in to comment.

More Answers (0)

Categories

Asked:

on 4 Aug 2024

Commented:

on 4 Aug 2024

Community Treasure Hunt

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

Start Hunting!