matlab模拟黑洞包含吸积盘和喷流,简单模拟

作者 : admin 本文共1348个字,预计阅读时间需要4分钟 发布时间: 2024-06-10 共2人阅读

本文介绍

黑洞的简单实现和模拟

代码

% Black Hole Simulation in 3D
% Clear workspace and figures
clear; close all; clc;
% Create figure and set axis properties
figure;
axis([-10 10 -10 10 -10 10]);
hold on;
grid on;
view(3);
% Parameters for the black hole and accretion disk
numParticles = 1000;  % Number of particles in the accretion disk
diskRadius = 5;       % Radius of the accretion disk
diskHeight = 0.5;     % Height of the accretion disk
jetHeight = 10;       % Height of the jet
jetRadius = 1;        % Radius of the jet
% Create particles for the accretion disk
theta = 2*pi*rand(numParticles,1);
r = diskRadius * sqrt(rand(numParticles,1));
x = r .* cos(theta);
y = r .* sin(theta);
z = diskHeight * (rand(numParticles,1) - 0.5);
% Create particles for the jet
jetParticles = 500;
jetX = jetRadius * (rand(jetParticles,1) - 0.5);
jetY = jetRadius * (rand(jetParticles,1) - 0.5);
jetZ = linspace(0, jetHeight, jetParticles)';
% Plot the black hole
[xSphere, ySphere, zSphere] = sphere(20);
surf(0.5*xSphere, 0.5*ySphere, 0.5*zSphere, 'FaceColor', 'k', 'EdgeColor', 'none');
% Plot the accretion disk
hDisk = scatter3(x, y, z, 1, 'r');
% Plot the jet
hJet = scatter3(jetX, jetY, jetZ, 1, 'b');
% Animation loop
numFrames = 200;
for t = 1:numFrames
% Update accretion disk particles (simple circular motion)
theta = theta + 0.1;
x = r .* cos(theta);
y = r .* sin(theta);
set(hDisk, 'XData', x, 'YData', y, 'ZData', z);
% Update jet particles (move upwards)
jetZ = jetZ + 0.1;
set(hJet, 'XData', jetX, 'YData', jetY, 'ZData', jetZ);
% Loop jet particles back to start
jetZ(jetZ > jetHeight) = 0;
% Pause to create animation effect
pause(0.05);
end

效果

matlab模拟黑洞包含吸积盘和喷流,简单模拟插图

本站无任何商业行为
个人在线分享 » matlab模拟黑洞包含吸积盘和喷流,简单模拟
E-->