basin for attraction of multiple attractor

36 ビュー (過去 30 日間)
Ajay
Ajay 2023 年 9 月 2 日
コメント済み: Kalyanashis 2024 年 2 月 9 日
how can basin of attraction of multiple attractor for a three dim system can plot as i am just able to plot only for one attractor and don't have an idea how to plotbasin of attraction for multiple attractor.
  3 件のコメント
Ajay
Ajay 2023 年 9 月 2 日
編集済み: Walter Roberson 2023 年 10 月 23 日
% Lorenz system parameters
clear all;
clc;
alpha = 10;
row= 28;
beta = 8/3;
% Define the Lorenz system equations
lorenz = @(t, xyz) [alpha * (xyz(2) - xyz(1));
xyz(1) * (row - xyz(3)) - xyz(2);
xyz(1) * xyz(2) - beta * xyz(3)];
% Define the attractor coordinates (you can adjust )
attractor = [0, 0, 0];
% Define the time span for simulation
tspan = [0, 5];
% Number of points for the grid
num_points = 20;
% Create a grid of initial conditions for x, y, and z
x_range = linspace(-30, 30, num_points);
y_range = linspace(-30, 30, num_points);
z_range = linspace(0, 50, num_points);
[X, Y, Z] = meshgrid(x_range, y_range, z_range);
% Create a colormap for plotting
colormap([1 0 0; 0 0 1]); % Red and blue
% Initialize a matrix to store basin of attraction information
basin = zeros(size(X));
% Loop through all initial conditions
for i = 1:numel(X)
x0 = X(i);
y0 = Y(i);
z0 = Z(i);
% Simulate the Lorenz system from (x0, y0, z0)
[~, sol] = ode45(lorenz, tspan, [x0, y0, z0]);
% Check if the trajectory converges to the attractor
if norm(sol(end, :) - attractor) < 1.0
% Mark this point as part of the basin of attraction
basin(i) = 1;
end
end
% Plot the basin of attraction
figure;
slice(X, Y, Z, basin, [], [], []);
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Basin of Attraction for Lorenz Attractor');
colorbar;
axis tight;
Kalyanashis
Kalyanashis 2023 年 10 月 18 日
This program will give a blank figure

サインインしてコメントする。

採用された回答

Varun
Varun 2023 年 9 月 11 日
編集済み: Varun 2023 年 9 月 11 日
Hi Ajay,
I understand that you are currently able to plot basin of attraction for one attractor, but you want to plot basin of attraction for multiple attractions.
To achieve this, you can modify the existing code by introducing an array of attractor coordinates. You define an array “attractor” that holds the coordinates of all the attractors you want to consider. .
Then, during the loop that checks if the trajectory converges to an attractor, you iterate over each attractor in the attractors array and break the loop as soon as a match is found. The value assigned to “basin(i)” represents the index of the attractor that the point converges to.
Please refer the updated code:
% Lorenz system parameters
clear all;
clc;
alpha = 10;
row= 28;
beta = 8/3;
% Define the Lorenz system equations
lorenz = @(t, xyz) [alpha * (xyz(2) - xyz(1));
xyz(1) * (row - xyz(3)) - xyz(2);
xyz(1) * xyz(2) - beta * xyz(3)];
% Define the attractor coordinates
attractors = [ % Add the coordinates of your attractors here
0, 0, 0;
10, -10, 20;
-10, 10, 30
];
% Define the time span for simulation
tspan = [0, 5];
% Number of points for the grid
num_points = 20;
% Create a grid of initial conditions for x, y, and z
x_range = linspace(-30, 30, num_points);
y_range = linspace(-30, 30, num_points);
z_range = linspace(0, 50, num_points);
[X, Y, Z] = meshgrid(x_range, y_range, z_range);
% Create a colormap for plotting
colormap([1 0 0; 0 0 1]); % Red and blue
% Initialize a matrix to store basin of attraction information
basin = zeros(size(X));
% Loop through all initial conditions
for i = 1:numel(X)
x0 = X(i);
y0 = Y(i);
z0 = Z(i);
% Simulate the Lorenz system from (x0, y0, z0)
[~, sol] = ode45(lorenz, tspan, [x0, y0, z0]);
% Check if the trajectory converges to any of the attractors
for j = 1:size(attractors, 1)
if norm(sol(end, :) - attractors(j, :)) < 1.0
% Mark this point as part of the basin of attraction
basin(i) = j; % Use the index of the attractor as the value
break; % Break the loop if a match is found
end
end
end
% Plot the basin of attraction
figure;
slice(X, Y, Z, basin, [], [], []);
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Basin of Attraction for Lorenz Attractors');
colorbar;
axis tight;
Hope this helps.
  7 件のコメント
Kalyanashis
Kalyanashis 2024 年 2 月 9 日
Kalyanashis
Kalyanashis 2024 年 2 月 9 日
This is the corresponding figure of your code

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by