basin for attraction of multiple attractor
23 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!